Skip to content

Commit

Permalink
chore: minor revision to new events
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewTriesToCode committed Nov 11, 2024
1 parent 3eb4596 commit 9bba985
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ public class StoreResolveCompletedContext<TTenantInfo>
where TTenantInfo : class, ITenantInfo, new()
{
/// <summary>
/// The MultiTenantStore instance that was run.
/// The MultiTenantStore instance that completed.
/// </summary>
public IMultiTenantStore<TTenantInfo> Store { get; init; }
public required IMultiTenantStore<TTenantInfo> Store { get; init; }

/// <summary>
/// The multiTenantStrategy that was used to resolve the tenant.
/// </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);

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
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

0 comments on commit 9bba985

Please sign in to comment.