@@ -22,8 +22,10 @@ namespace Finbuckle.MultiTenant;
22
22
public static class MultiTenantBuilderExtensions
23
23
{
24
24
/// <summary>
25
- /// Adds a DistributedCacheStore to the application.
25
+ /// Adds a DistributedCacheStore to the application with maximum sliding expiration .
26
26
/// </summary>
27
+ /// <typeparam name="TTenantInfo">The ITenantInfo implementation type.</typeparam>
28
+ /// <returns>The <see cref="MultiTenantBuilder<TTenantInfo>"/> so that additional calls can be chained.</returns>
27
29
public static MultiTenantBuilder < TTenantInfo > WithDistributedCacheStore < TTenantInfo > ( this MultiTenantBuilder < TTenantInfo > builder )
28
30
where TTenantInfo : class , ITenantInfo , new ( )
29
31
=> builder . WithDistributedCacheStore ( TimeSpan . MaxValue ) ;
@@ -32,8 +34,10 @@ public static MultiTenantBuilder<TTenantInfo> WithDistributedCacheStore<TTenantI
32
34
/// <summary>
33
35
/// Adds a DistributedCacheStore to the application.
34
36
/// </summary>
37
+ /// <typeparam name="TTenantInfo">The ITenantInfo implementation type.</typeparam>
35
38
/// <param name="builder">The builder instance.</param>
36
39
/// <param name="slidingExpiration">The timespan for a cache entry's sliding expiration.</param>
40
+ /// <returns>The <see cref="MultiTenantBuilder<TTenantInfo>"/> so that additional calls can be chained.</returns>
37
41
public static MultiTenantBuilder < TTenantInfo > WithDistributedCacheStore < TTenantInfo > ( this MultiTenantBuilder < TTenantInfo > builder , TimeSpan ? slidingExpiration )
38
42
where TTenantInfo : class , ITenantInfo , new ( )
39
43
{
@@ -45,18 +49,22 @@ public static MultiTenantBuilder<TTenantInfo> WithDistributedCacheStore<TTenantI
45
49
/// <summary>
46
50
/// Adds a HttpRemoteStore to the application.
47
51
/// </summary>
52
+ /// <typeparam name="TTenantInfo">The ITenantInfo implementation type.</typeparam>
48
53
/// <param name="builder">The builder instance.</param>
49
54
/// <param name="endpointTemplate">The endpoint URI template.</param>
55
+ /// <returns>The <see cref="MultiTenantBuilder<TTenantInfo>"/> so that additional calls can be chained.</returns>
50
56
public static MultiTenantBuilder < TTenantInfo > WithHttpRemoteStore < TTenantInfo > ( this MultiTenantBuilder < TTenantInfo > builder , string endpointTemplate )
51
57
where TTenantInfo : class , ITenantInfo , new ( )
52
58
=> builder . WithHttpRemoteStore ( endpointTemplate , null ) ;
53
59
54
60
/// <summary>
55
61
/// Adds a HttpRemoteStore to the application.
56
62
/// </summary>
63
+ /// <typeparam name="TTenantInfo">The ITenantInfo implementation type.</typeparam>
57
64
/// <param name="builder">The builder instance.</param>
58
65
/// <param name="endpointTemplate">The endpoint URI template.</param>
59
66
/// <param name="clientConfig">An action to configure the underlying HttpClient.</param>
67
+ /// <returns>The <see cref="MultiTenantBuilder<TTenantInfo>"/> so that additional calls can be chained.</returns>
60
68
public static MultiTenantBuilder < TTenantInfo > WithHttpRemoteStore < TTenantInfo > ( this MultiTenantBuilder < TTenantInfo > builder ,
61
69
string endpointTemplate ,
62
70
Action < IHttpClientBuilder > ? clientConfig ) where TTenantInfo : class , ITenantInfo , new ( )
@@ -72,17 +80,21 @@ public static MultiTenantBuilder<TTenantInfo> WithHttpRemoteStore<TTenantInfo>(t
72
80
/// <summary>
73
81
/// Adds a ConfigurationStore to the application. Uses the default IConfiguration and section "Finbuckle:MultiTenant:Stores:ConfigurationStore".
74
82
/// </summary>
83
+ /// <typeparam name="TTenantInfo">The ITenantInfo implementation type.</typeparam>
75
84
/// <param name="builder">The builder instance.</param>
85
+ /// <returns>The <see cref="MultiTenantBuilder<TTenantInfo>"/> so that additional calls can be chained.</returns>
76
86
public static MultiTenantBuilder < TTenantInfo > WithConfigurationStore < TTenantInfo > ( this MultiTenantBuilder < TTenantInfo > builder )
77
87
where TTenantInfo : class , ITenantInfo , new ( )
78
88
=> builder . WithStore < ConfigurationStore < TTenantInfo > > ( ServiceLifetime . Singleton ) ;
79
89
80
90
/// <summary>
81
91
/// Adds a ConfigurationStore to the application.
82
92
/// </summary>
93
+ /// <typeparam name="TTenantInfo">The ITenantInfo implementation type.</typeparam>
83
94
/// <param name="builder">The builder instance.</param>
84
95
/// <param name="configuration">The IConfiguration to load the section from.</param>
85
96
/// <param name="sectionName">The configuration section to load.</param>
97
+ /// <returns>The <see cref="MultiTenantBuilder<TTenantInfo>"/> so that additional calls can be chained.</returns>
86
98
public static MultiTenantBuilder < TTenantInfo > WithConfigurationStore < TTenantInfo > ( this MultiTenantBuilder < TTenantInfo > builder ,
87
99
IConfiguration configuration ,
88
100
string sectionName )
@@ -92,17 +104,20 @@ public static MultiTenantBuilder<TTenantInfo> WithConfigurationStore<TTenantInfo
92
104
/// <summary>
93
105
/// Adds an empty InMemoryStore to the application.
94
106
/// </summary>
107
+ /// <typeparam name="TTenantInfo">The ITenantInfo implementation type.</typeparam>
95
108
/// <param name="builder">The builder instance.</param>
109
+ /// <returns>The <see cref="MultiTenantBuilder<TTenantInfo>"/> so that additional calls can be chained.</returns>
96
110
public static MultiTenantBuilder < TTenantInfo > WithInMemoryStore < TTenantInfo > ( this MultiTenantBuilder < TTenantInfo > builder )
97
111
where TTenantInfo : class , ITenantInfo , new ( )
98
- // ReSharper disable once RedundantTypeArgumentsOfMethod
99
- => builder . WithInMemoryStore < TTenantInfo > ( _ => { } ) ;
112
+ => builder . WithInMemoryStore ( _ => { } ) ;
100
113
101
114
/// <summary>
102
115
/// Adds and configures InMemoryStore to the application using the provided action.
103
116
/// </summary>
117
+ /// <typeparam name="TTenantInfo">The ITenantInfo implementation type.</typeparam>
104
118
/// <param name="builder">The builder instance.</param>
105
119
/// <param name="config">An action for configuring the store.</param>
120
+ /// <returns>The <see cref="MultiTenantBuilder<TTenantInfo>"/> so that additional calls can be chained.</returns>
106
121
public static MultiTenantBuilder < TTenantInfo > WithInMemoryStore < TTenantInfo > ( this MultiTenantBuilder < TTenantInfo > builder ,
107
122
Action < InMemoryStoreOptions < TTenantInfo > > config )
108
123
where TTenantInfo : class , ITenantInfo , new ( )
@@ -121,16 +136,20 @@ public static MultiTenantBuilder<TTenantInfo> WithInMemoryStore<TTenantInfo>(thi
121
136
/// <summary>
122
137
/// Adds an EchoStore to the application.
123
138
/// </summary>
139
+ /// <typeparam name="TTenantInfo">The ITenantInfo implementation type.</typeparam>
124
140
/// <param name="builder">The builder instance.</param>
141
+ /// <returns>The <see cref="MultiTenantBuilder<TTenantInfo>"/> so that additional calls can be chained.</returns>
125
142
public static MultiTenantBuilder < TTenantInfo > WithEchoStore < TTenantInfo > ( this MultiTenantBuilder < TTenantInfo > builder )
126
143
where TTenantInfo : class , ITenantInfo , new ( )
127
144
=> builder . WithStore < EchoStore < TTenantInfo > > ( ServiceLifetime . Singleton ) ;
128
145
129
146
/// <summary>
130
147
/// Adds and configures a StaticStrategy to the application.
131
148
/// </summary>
149
+ /// <typeparam name="TTenantInfo">The ITenantInfo implementation type.</typeparam>
132
150
/// <param name="builder">The builder instance.</param>
133
151
/// <param name="identifier">The tenant identifier to use for all tenant resolution.</param>
152
+ /// <returns>The <see cref="MultiTenantBuilder<TTenantInfo>"/> so that additional calls can be chained.</returns>
134
153
public static MultiTenantBuilder < TTenantInfo > WithStaticStrategy < TTenantInfo > ( this MultiTenantBuilder < TTenantInfo > builder ,
135
154
string identifier )
136
155
where TTenantInfo : class , ITenantInfo , new ( )
@@ -146,8 +165,10 @@ public static MultiTenantBuilder<TTenantInfo> WithStaticStrategy<TTenantInfo>(th
146
165
/// <summary>
147
166
/// Adds and configures a DelegateStrategy to the application.
148
167
/// </summary>
168
+ /// <typeparam name="TTenantInfo">The ITenantInfo implementation type.</typeparam>
149
169
/// <param name="builder">The builder instance.</param>
150
170
/// <param name="doStrategy">The delegate implementing the strategy.</param>
171
+ /// <returns>The <see cref="MultiTenantBuilder<TTenantInfo>"/> so that additional calls can be chained.</returns>
151
172
public static MultiTenantBuilder < TTenantInfo > WithDelegateStrategy < TTenantInfo > ( this MultiTenantBuilder < TTenantInfo > builder ,
152
173
Func < object , Task < string ? > > doStrategy )
153
174
where TTenantInfo : class , ITenantInfo , new ( )
@@ -159,4 +180,31 @@ public static MultiTenantBuilder<TTenantInfo> WithDelegateStrategy<TTenantInfo>(
159
180
160
181
return builder . WithStrategy < DelegateStrategy > ( ServiceLifetime . Singleton , new object [ ] { doStrategy } ) ;
161
182
}
183
+
184
+ /// <summary>
185
+ /// Adds and configures a typed DelegateStrategy<TContext> to the application.
186
+ /// </summary>
187
+ /// <typeparam name="TContext">The strategy context type.</typeparam>
188
+ /// <typeparam name="TTenantInfo">The ITenantInfo implementation type.</typeparam>
189
+ /// <param name="builder"></param>
190
+ /// <param name="doStrategy"></param>
191
+ /// <returns>The <see cref="MultiTenantBuilder<TTenantInfo>"/> so that additional calls can be chained.</returns>
192
+ public static MultiTenantBuilder < TTenantInfo > WithDelegateStrategy < TContext , TTenantInfo > ( this MultiTenantBuilder < TTenantInfo > builder ,
193
+ Func < TContext , Task < string ? > > doStrategy )
194
+ where TTenantInfo : class , ITenantInfo , new ( )
195
+ {
196
+ ArgumentNullException . ThrowIfNull ( doStrategy , nameof ( doStrategy ) ) ;
197
+
198
+ Func < object , Task < string ? > > wrapStrategy = context =>
199
+ {
200
+ if ( context . GetType ( ) == typeof ( TContext ) )
201
+ {
202
+ return doStrategy ( ( TContext ) context ) ;
203
+ }
204
+
205
+ return Task . FromResult < string ? > ( null ) ;
206
+ } ;
207
+
208
+ return builder . WithDelegateStrategy ( wrapStrategy ) ;
209
+ }
162
210
}
0 commit comments