@@ -38,47 +38,47 @@ public TenantResolver(IEnumerable<IMultiTenantStrategy> strategies, IEnumerable<
38
38
39
39
public async Task < IMultiTenantContext < T > ? > ResolveAsync ( object context )
40
40
{
41
- IMultiTenantContext < T > ? result = null ;
42
-
41
+ string ? identifier = null ;
43
42
foreach ( var strategy in Strategies )
44
43
{
45
44
var _strategy = new MultiTenantStrategyWrapper ( strategy , loggerFactory ? . CreateLogger ( strategy . GetType ( ) ) ?? NullLogger . Instance ) ;
46
- var identifier = await _strategy . GetIdentifierAsync ( context ) ;
45
+ identifier = await _strategy . GetIdentifierAsync ( context ) ;
47
46
48
47
if ( options . CurrentValue . IgnoredIdentifiers . Contains ( identifier , StringComparer . OrdinalIgnoreCase ) )
49
48
{
50
49
( loggerFactory ? . CreateLogger ( GetType ( ) ) ?? NullLogger . Instance ) . LogInformation ( "Ignored identifier: {Identifier}" , identifier ) ;
51
50
identifier = null ;
52
51
}
52
+
53
+ if ( identifier == null )
54
+ continue ;
53
55
54
- if ( identifier != null )
56
+ foreach ( var store in Stores )
55
57
{
56
- foreach ( var store in Stores )
57
- {
58
- var _store = new MultiTenantStoreWrapper < T > ( store , loggerFactory ? . CreateLogger ( store . GetType ( ) ) ?? NullLogger . Instance ) ;
59
- var tenantInfo = await _store . TryGetByIdentifierAsync ( identifier ) ;
60
- if ( tenantInfo != null )
61
- {
62
- result = new MultiTenantContext < T > ( ) ;
63
- result . StoreInfo = new StoreInfo < T > { Store = store , StoreType = store . GetType ( ) } ;
64
- result . StrategyInfo = new StrategyInfo { Strategy = strategy , StrategyType = strategy . GetType ( ) } ;
65
- result . TenantInfo = tenantInfo ;
66
-
67
- await options . CurrentValue . Events . OnTenantResolved ( new TenantResolvedContext { Context =
68
- context , TenantInfo = tenantInfo , StrategyType = strategy . GetType ( ) , StoreType = store . GetType ( ) } ) ;
69
-
70
- break ;
71
- }
72
- }
58
+ var _store = new MultiTenantStoreWrapper < T > ( store , loggerFactory ? . CreateLogger ( store . GetType ( ) ) ?? NullLogger . Instance ) ;
59
+ var tenantInfo = await _store . TryGetByIdentifierAsync ( identifier ) ;
60
+ if ( tenantInfo == null )
61
+ continue ;
73
62
74
- if ( result != null )
75
- break ;
76
-
77
- await options . CurrentValue . Events . OnTenantNotResolved ( new TenantNotResolvedContext { Context = context , Identifier = identifier } ) ;
63
+ await options . CurrentValue . Events . OnTenantResolved ( new TenantResolvedContext
64
+ {
65
+ Context = context ,
66
+ TenantInfo = tenantInfo ,
67
+ StrategyType = strategy . GetType ( ) ,
68
+ StoreType = store . GetType ( )
69
+ } ) ;
70
+
71
+ return new MultiTenantContext < T >
72
+ {
73
+ StoreInfo = new StoreInfo < T > { Store = store , StoreType = store . GetType ( ) } ,
74
+ StrategyInfo = new StrategyInfo { Strategy = strategy , StrategyType = strategy . GetType ( ) } ,
75
+ TenantInfo = tenantInfo
76
+ } ;
78
77
}
79
78
}
80
-
81
- return result ;
79
+
80
+ await options . CurrentValue . Events . OnTenantNotResolved ( new TenantNotResolvedContext { Context = context , Identifier = identifier } ) ;
81
+ return null ;
82
82
}
83
83
84
84
// TODO move this to the base interface?
0 commit comments