Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: event fixup #899

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ public class StoreResolveCompletedContext<TTenantInfo>
/// <summary>
/// The MultiTenantStore instance that was run.
/// </summary>
public IMultiTenantStore<TTenantInfo> Store { get; init; }
public required IMultiTenantStore<TTenantInfo> Store { get; init; }

/// <summary>
/// The MultiTenantStrategy instance that was run.
/// </summary>
public required IMultiTenantStrategy Strategy { get; init; }

/// <summary>
/// The identifier used for tenant resolution by the store.
Expand Down
33 changes: 18 additions & 15 deletions src/Finbuckle.MultiTenant/TenantResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,17 @@ public async Task<IMultiTenantContext<TTenantInfo>> ResolveAsync(object context)
foreach (var strategy in Strategies)
{
var strategyLogger = loggerFactory?.CreateLogger(strategy.GetType()) ?? NullLogger.Instance;

var wrappedStrategy = new MultiTenantStrategyWrapper(strategy, strategyLogger);
identifier = await wrappedStrategy.GetIdentifierAsync(context);

var strategyResolveCompletedContext = new StrategyResolveCompletedContext { Context = context, Strategy = strategy, Identifier = identifier };

var strategyResolveCompletedContext = new StrategyResolveCompletedContext
{ Context = context, Strategy = strategy, Identifier = identifier };
await options.CurrentValue.Events.OnStrategyResolveCompleted(strategyResolveCompletedContext);
if(identifier is not null && strategyResolveCompletedContext.Identifier is null)
if (identifier is not null && strategyResolveCompletedContext.Identifier is null)
tenantResoloverLogger.LogDebug("OnStrategyResolveCompleted set non-null Identifier to null");
identifier = strategyResolveCompletedContext.Identifier;

if (options.CurrentValue.IgnoredIdentifiers.Contains(identifier, StringComparer.OrdinalIgnoreCase))
{
tenantResoloverLogger.LogDebug("Ignored identifier: {Identifier}", identifier);
Expand All @@ -76,34 +77,36 @@ public async Task<IMultiTenantContext<TTenantInfo>> ResolveAsync(object context)
foreach (var store in Stores)
{
var storeLogger = loggerFactory?.CreateLogger(store.GetType()) ?? NullLogger.Instance;

var wrappedStore = new MultiTenantStoreWrapper<TTenantInfo>(store, storeLogger);
var tenantInfo = await wrappedStore.TryGetByIdentifierAsync(identifier);

var storeResolveCompletedContext = new StoreResolveCompletedContext<TTenantInfo> { Store = store, Identifier = identifier, TenantInfo = tenantInfo };

var storeResolveCompletedContext = new StoreResolveCompletedContext<TTenantInfo>
{ Store = store, Strategy = strategy, Identifier = identifier, TenantInfo = tenantInfo };
await options.CurrentValue.Events.OnStoreResolveCompleted(storeResolveCompletedContext);
if(tenantInfo is not null && storeResolveCompletedContext.TenantInfo is null)
if (tenantInfo is not null && storeResolveCompletedContext.TenantInfo is null)
tenantResoloverLogger.LogDebug("OnStoreResolveCompleted set non-null TenantInfo to null");
tenantInfo = storeResolveCompletedContext.TenantInfo;

if (tenantInfo != null)
{
mtc.StoreInfo = new StoreInfo<TTenantInfo> { Store = store, StoreType = store.GetType() };
mtc.StrategyInfo = new StrategyInfo { Strategy = strategy, StrategyType = strategy.GetType() };
mtc.TenantInfo = tenantInfo;
}

// no longer check stores if tenant is resolved
if(mtc.IsResolved)
if (mtc.IsResolved)
break;
}

// no longer check strategies if tenant is resolved
if(mtc.IsResolved)
if (mtc.IsResolved)
break;
}

var resolutionCompletedContext = new TenantResolveCompletedContext<TTenantInfo>{ MultiTenantContext = mtc, Context = context };
var resolutionCompletedContext = new TenantResolveCompletedContext<TTenantInfo>
{ MultiTenantContext = mtc, Context = context };
await options.CurrentValue.Events.OnTenantResolveCompleted(resolutionCompletedContext);
return resolutionCompletedContext.MultiTenantContext;
}
Expand Down