@@ -37,14 +37,15 @@ public class DynamicProviderStore<TSchemeDefinition> : IDynamicProviderStore<TSc
37
37
private readonly IAsyncDocumentSession _session ;
38
38
private readonly IAuthenticationSchemeOptionsSerializer _authenticationSchemeOptionsSerializer ;
39
39
private readonly ILogger < DynamicProviderStore < TSchemeDefinition > > _logger ;
40
+ private readonly string _entitybasePath ;
40
41
41
42
/// <summary>
42
43
/// Gets the scheme definitions list.
43
44
/// </summary>
44
45
/// <value>
45
46
/// The scheme definitions list.
46
47
/// </value>
47
- public virtual IQueryable < TSchemeDefinition > SchemeDefinitions => _session . Query < SerializedData > ( )
48
+ public virtual IQueryable < TSchemeDefinition > SchemeDefinitions => _session . Query < TSchemeDefinition > ( )
48
49
. ToListAsync ( ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( )
49
50
. Select ( Deserialize )
50
51
. AsQueryable ( ) ;
@@ -67,6 +68,7 @@ public DynamicProviderStore(IAsyncDocumentSession session, IAuthenticationScheme
67
68
_session = session ?? throw new ArgumentNullException ( nameof ( session ) ) ;
68
69
_authenticationSchemeOptionsSerializer = authenticationSchemeOptionsSerializer ?? throw new ArgumentNullException ( nameof ( authenticationSchemeOptionsSerializer ) ) ;
69
70
_logger = logger ?? throw new ArgumentNullException ( nameof ( logger ) ) ;
71
+ _entitybasePath = typeof ( TSchemeDefinition ) . Name . ToLower ( ) + "/" ;
70
72
}
71
73
72
74
/// <summary>
@@ -83,7 +85,7 @@ public virtual async Task AddAsync(TSchemeDefinition definition, CancellationTok
83
85
cancellationToken . ThrowIfCancellationRequested ( ) ;
84
86
85
87
var data = Serialize ( definition ) ;
86
- await _session . StoreAsync ( data , cancellationToken ) . ConfigureAwait ( false ) ;
88
+ await _session . StoreAsync ( data , $ " { _entitybasePath } { definition . Scheme } " , cancellationToken ) . ConfigureAwait ( false ) ;
87
89
await _session . SaveChangesAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
88
90
89
91
_logger . LogInformation ( "Scheme {scheme} added for {handlerType} with options: {options}" , definition . Scheme , definition . HandlerType , data . SerializedOptions ) ;
@@ -102,7 +104,7 @@ public virtual async Task RemoveAsync(TSchemeDefinition definition, Cancellation
102
104
103
105
cancellationToken . ThrowIfCancellationRequested ( ) ;
104
106
105
- var data = await _session . LoadAsync < SerializedData > ( definition . Scheme , cancellationToken ) . ConfigureAwait ( false ) ;
107
+ var data = await _session . LoadAsync < TSchemeDefinition > ( $ " { _entitybasePath } { definition . Scheme } " , cancellationToken ) . ConfigureAwait ( false ) ;
106
108
_session . Delete ( data ) ;
107
109
await _session . SaveChangesAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
108
110
@@ -124,7 +126,7 @@ public virtual async Task UpdateAsync(TSchemeDefinition definition, Cancellation
124
126
125
127
var serialized = Serialize ( definition ) ;
126
128
127
- var data = await _session . LoadAsync < SerializedData > ( definition . Scheme , cancellationToken ) . ConfigureAwait ( false ) ;
129
+ var data = await _session . LoadAsync < TSchemeDefinition > ( $ " { _entitybasePath } { definition . Scheme } " , cancellationToken ) . ConfigureAwait ( false ) ;
128
130
129
131
data . SerializedOptions = serialized . SerializedOptions ;
130
132
data . SerializedHandlerType = serialized . SerializedHandlerType ;
@@ -149,7 +151,7 @@ public virtual async Task<TSchemeDefinition> FindBySchemeAsync(string scheme, Ca
149
151
CheckScheme ( scheme ) ;
150
152
151
153
cancellationToken . ThrowIfCancellationRequested ( ) ;
152
- var data = await _session . LoadAsync < SerializedData > ( scheme , cancellationToken ) . ConfigureAwait ( false ) ;
154
+ var data = await _session . LoadAsync < TSchemeDefinition > ( $ " { _entitybasePath } { scheme } " , cancellationToken ) . ConfigureAwait ( false ) ;
153
155
154
156
if ( data != null )
155
157
{
@@ -167,35 +169,22 @@ private static void CheckScheme(string scheme)
167
169
}
168
170
}
169
171
170
- private SerializedData Serialize ( TSchemeDefinition definition )
172
+ private TSchemeDefinition Serialize ( TSchemeDefinition definition )
171
173
{
172
- return new SerializedData
173
- {
174
- Id = definition . Scheme ,
175
- SerializedHandlerType = _authenticationSchemeOptionsSerializer . SerializeType ( definition . HandlerType ) ,
176
- SerializedOptions = _authenticationSchemeOptionsSerializer . SerializeOptions ( definition . Options , definition . HandlerType . GetAuthenticationSchemeOptionsType ( ) )
177
- } ;
174
+ var data = ( TSchemeDefinition ) definition . Clone ( ) ;
175
+ data . SerializedHandlerType = _authenticationSchemeOptionsSerializer . SerializeType ( definition . HandlerType ) ;
176
+ data . SerializedOptions = _authenticationSchemeOptionsSerializer . SerializeOptions ( definition . Options , definition . HandlerType . GetAuthenticationSchemeOptionsType ( ) ) ;
177
+ data . HandlerType = null ;
178
+ data . Options = null ;
179
+ return data ;
178
180
}
179
181
180
- private TSchemeDefinition Deserialize ( SerializedData data )
182
+ private TSchemeDefinition Deserialize ( TSchemeDefinition data )
181
183
{
182
184
var handlerType = _authenticationSchemeOptionsSerializer . DeserializeType ( data . SerializedHandlerType ) ;
183
- return new TSchemeDefinition
184
- {
185
- Scheme = data . Id ,
186
- HandlerType = handlerType ,
187
- Options = _authenticationSchemeOptionsSerializer . DeserializeOptions ( data . SerializedOptions , handlerType . GetAuthenticationSchemeOptionsType ( ) )
188
- } ;
189
- }
190
-
191
- class SerializedData
192
- {
193
- public string Id { get ; set ; }
194
-
195
- public string SerializedOptions { get ; set ; }
196
-
197
- public string SerializedHandlerType { get ; set ; }
198
-
199
- }
185
+ data . HandlerType = handlerType ;
186
+ data . Options = _authenticationSchemeOptionsSerializer . DeserializeOptions ( data . SerializedOptions , handlerType . GetAuthenticationSchemeOptionsType ( ) ) ;
187
+ return data ;
188
+ }
200
189
}
201
190
}
0 commit comments