@@ -96,16 +96,28 @@ await _optionsMonitor.GetAsync(schemaName, cancellationToken)
96
96
setup . SchemaBuilder ?? new SchemaBuilder ( ) ,
97
97
_applicationServices ) ;
98
98
99
+
100
+ var typeModuleChangeMonitor = new TypeModuleChangeMonitor ( this , context . SchemaName ) ;
101
+
102
+ // if there are any type modules we will register them with the
103
+ // type module change monitor.
104
+ // The module will track if type modules signal changes to the schema and
105
+ // start a schema eviction.
106
+ foreach ( var typeModule in setup . TypeModules )
107
+ {
108
+ typeModuleChangeMonitor . Register ( typeModule ) ;
109
+ }
110
+
99
111
var schemaServices =
100
- await CreateSchemaServicesAsync ( context , setup , cancellationToken )
112
+ await CreateSchemaServicesAsync ( context , setup , typeModuleChangeMonitor , cancellationToken )
101
113
. ConfigureAwait ( false ) ;
102
114
103
115
registeredExecutor = new RegisteredExecutor (
104
116
schemaServices . GetRequiredService < IRequestExecutor > ( ) ,
105
117
schemaServices ,
106
118
schemaServices . GetRequiredService < IExecutionDiagnosticEvents > ( ) ,
107
119
setup ,
108
- schemaServices . GetRequiredService < TypeModuleChangeMonitor > ( ) ) ;
120
+ typeModuleChangeMonitor ) ;
109
121
110
122
var executor = registeredExecutor . Executor ;
111
123
@@ -131,24 +143,26 @@ public void EvictRequestExecutor(string? schemaName = default)
131
143
{
132
144
schemaName ??= Schema . DefaultName ;
133
145
134
- if ( _executors . TryRemove ( schemaName , out var re ) )
146
+ if ( _executors . TryRemove ( schemaName , out var executor ) )
135
147
{
136
- re . DiagnosticEvents . ExecutorEvicted ( schemaName , re . Executor ) ;
148
+ executor . DiagnosticEvents . ExecutorEvicted ( schemaName , executor . Executor ) ;
137
149
138
150
try
139
151
{
152
+ executor . TypeModuleChangeMonitor . Dispose ( ) ;
153
+
140
154
RequestExecutorEvicted ? . Invoke (
141
155
this ,
142
- new RequestExecutorEvictedEventArgs ( schemaName , re . Executor ) ) ;
156
+ new RequestExecutorEvictedEventArgs ( schemaName , executor . Executor ) ) ;
143
157
_events . RaiseEvent (
144
158
new RequestExecutorEvent (
145
159
RequestExecutorEventType . Evicted ,
146
160
schemaName ,
147
- re . Executor ) ) ;
161
+ executor . Executor ) ) ;
148
162
}
149
163
finally
150
164
{
151
- BeginRunEvictionEvents ( re ) ;
165
+ BeginRunEvictionEvents ( executor ) ;
152
166
}
153
167
}
154
168
}
@@ -157,26 +171,7 @@ private void EvictAllRequestExecutors()
157
171
{
158
172
foreach ( var key in _executors . Keys )
159
173
{
160
- if ( _executors . TryRemove ( key , out var re ) )
161
- {
162
- re . DiagnosticEvents . ExecutorEvicted ( key , re . Executor ) ;
163
-
164
- try
165
- {
166
- RequestExecutorEvicted ? . Invoke (
167
- this ,
168
- new RequestExecutorEvictedEventArgs ( key , re . Executor ) ) ;
169
- _events . RaiseEvent (
170
- new RequestExecutorEvent (
171
- RequestExecutorEventType . Evicted ,
172
- key ,
173
- re . Executor ) ) ;
174
- }
175
- finally
176
- {
177
- BeginRunEvictionEvents ( re ) ;
178
- }
179
- }
174
+ EvictRequestExecutor ( key ) ;
180
175
}
181
176
}
182
177
@@ -201,6 +196,7 @@ private static async Task RunEvictionEvents(RegisteredExecutor registeredExecuto
201
196
private async Task < IServiceProvider > CreateSchemaServicesAsync (
202
197
ConfigurationContext context ,
203
198
RequestExecutorSetup setup ,
199
+ TypeModuleChangeMonitor typeModuleChangeMonitor ,
204
200
CancellationToken cancellationToken )
205
201
{
206
202
ulong version ;
@@ -211,22 +207,12 @@ private async Task<IServiceProvider> CreateSchemaServicesAsync(
211
207
}
212
208
213
209
var serviceCollection = new ServiceCollection ( ) ;
214
- var typeModuleChangeMonitor = new TypeModuleChangeMonitor ( this , context . SchemaName ) ;
215
210
var lazy = new SchemaBuilder . LazySchema ( ) ;
216
211
217
212
var executorOptions =
218
213
await OnConfigureRequestExecutorOptionsAsync ( context , setup , cancellationToken )
219
214
. ConfigureAwait ( false ) ;
220
215
221
- // if there are any type modules we will register them with the
222
- // type module change monitor.
223
- // The module will track if type modules signal changes to the schema and
224
- // start a schema eviction.
225
- foreach ( var typeModule in setup . TypeModules )
226
- {
227
- typeModuleChangeMonitor . Register ( typeModule ) ;
228
- }
229
-
230
216
// we allow newer type modules to apply configurations.
231
217
await typeModuleChangeMonitor . ConfigureAsync ( context , cancellationToken )
232
218
. ConfigureAwait ( false ) ;
@@ -241,7 +227,6 @@ await typeModuleChangeMonitor.ConfigureAsync(context, cancellationToken)
241
227
setup . DefaultPipelineFactory ,
242
228
setup . Pipeline ) ) ;
243
229
244
- serviceCollection . AddSingleton ( typeModuleChangeMonitor ) ;
245
230
serviceCollection . AddSingleton ( executorOptions ) ;
246
231
serviceCollection . AddSingleton < IRequestExecutorOptionsAccessor > (
247
232
static s => s . GetRequiredService < RequestExecutorOptions > ( ) ) ;
0 commit comments