@@ -34,8 +34,6 @@ public class ResourceHookExecutor : IResourceHookExecutor
34
34
protected readonly IHookExecutorHelper _meta ;
35
35
protected readonly IJsonApiContext _context ;
36
36
private readonly IResourceGraph _graph ;
37
- protected Dictionary < Type , HashSet < IIdentifiable > > _processedEntities ;
38
-
39
37
40
38
public ResourceHookExecutor (
41
39
IHookExecutorHelper meta ,
@@ -46,8 +44,7 @@ IResourceGraph graph
46
44
_meta = meta ;
47
45
_context = context ;
48
46
_graph = graph ;
49
- _processedEntities = new Dictionary < Type , HashSet < IIdentifiable > > ( ) ;
50
- _layerFactory = new EntityTreeLayerFactory ( meta , graph , _context , _processedEntities ) ;
47
+ _layerFactory = new EntityTreeLayerFactory ( meta , graph , _context ) ;
51
48
}
52
49
53
50
@@ -64,8 +61,6 @@ public virtual void BeforeRead<TEntity>(ResourceAction pipeline, string stringId
64
61
// TODO: Get rid of nested boolean and calledContainers, add BeforeReadRelation hook
65
62
RecursiveBeforeRead ( contextEntity , relationshipPath . Split ( '.' ) . ToList ( ) , pipeline , calledContainers ) ;
66
63
}
67
-
68
-
69
64
}
70
65
71
66
void RecursiveBeforeRead ( ContextEntity contextEntity , List < string > relationshipChain , ResourceAction pipeline , List < Type > calledContainers )
@@ -111,7 +106,6 @@ public virtual IEnumerable<TEntity> BeforeUpdate<TEntity>(IEnumerable<TEntity> e
111
106
}
112
107
EntityTreeLayer nextLayer = _layerFactory . CreateLayer ( layer ) ;
113
108
BeforeUpdateRelationship ( pipeline , nextLayer ) ;
114
- FlushRegister ( ) ;
115
109
return entities ;
116
110
}
117
111
@@ -128,7 +122,6 @@ public virtual IEnumerable<TEntity> BeforeCreate<TEntity>(IEnumerable<TEntity> e
128
122
EntityTreeLayer nextLayer = _layerFactory . CreateLayer ( layer ) ;
129
123
130
124
BeforeUpdateRelationship ( pipeline , nextLayer ) ;
131
- FlushRegister ( ) ;
132
125
return entities ;
133
126
}
134
127
@@ -219,26 +212,24 @@ public virtual IEnumerable<TEntity> BeforeDelete<TEntity>(IEnumerable<TEntity> e
219
212
}
220
213
}
221
214
222
- FlushRegister ( ) ;
223
215
return entities ;
224
216
225
217
}
226
218
227
219
public virtual IEnumerable < TEntity > OnReturn < TEntity > ( IEnumerable < TEntity > entities , ResourceAction pipeline ) where TEntity : class , IIdentifiable
228
220
{
229
- var hookContainer = _meta . GetResourceHookContainer < TEntity > ( ResourceHook . AfterRead ) ;
221
+ var hookContainer = _meta . GetResourceHookContainer < TEntity > ( ResourceHook . OnReturn ) ;
230
222
var layer = _layerFactory . CreateLayer ( entities ) ;
231
223
if ( hookContainer != null )
232
224
{
233
225
var uniqueEntities = layer . GetAllUniqueEntities ( ) . Cast < TEntity > ( ) ;
234
- var filteredUniqueEntities = hookContainer ? . OnReturn ( uniqueEntities , pipeline ) ;
226
+ var filteredUniqueEntities = hookContainer . OnReturn ( uniqueEntities , pipeline ) ;
235
227
/// this is not updating unique entities internally!!!! say [a_1, a_2] => [a_1],
236
228
/// then nested hooks for relations of a_2 are still being fired
237
229
entities = entities . Intersect ( filteredUniqueEntities , Comparer ) . Cast < TEntity > ( ) ;
238
230
}
239
231
var nextLayer = _layerFactory . CreateLayer ( layer ) ;
240
232
RecursiveOnReturn ( nextLayer , pipeline ) ;
241
- FlushRegister ( ) ;
242
233
return entities ;
243
234
}
244
235
@@ -247,7 +238,7 @@ void RecursiveOnReturn(EntityTreeLayer currentLayer, ResourceAction pipeline)
247
238
foreach ( NodeInLayer node in currentLayer )
248
239
{
249
240
var entityType = node . EntityType ;
250
- var hookContainer = _meta . GetResourceHookContainer ( entityType , ResourceHook . AfterRead ) ;
241
+ var hookContainer = _meta . GetResourceHookContainer ( entityType , ResourceHook . OnReturn ) ;
251
242
if ( hookContainer == null ) continue ;
252
243
253
244
var filteredUniqueSet = CallHook ( hookContainer , ResourceHook . OnReturn , new object [ ] { node . UniqueSet , pipeline } ) . Cast < IIdentifiable > ( ) ;
@@ -286,19 +277,17 @@ void Reassign(NodeInLayer node)
286
277
}
287
278
}
288
279
289
-
290
280
public virtual void AfterRead < TEntity > ( IEnumerable < TEntity > entities , ResourceAction pipeline ) where TEntity : class , IIdentifiable
291
281
{
292
282
var hookContainer = _meta . GetResourceHookContainer < TEntity > ( ResourceHook . AfterCreate ) ;
293
283
var layer = _layerFactory . CreateLayer ( entities ) ;
294
284
if ( hookContainer != null )
295
285
{
296
286
var uniqueEntities = layer . GetAllUniqueEntities ( ) . Cast < TEntity > ( ) ;
297
- hookContainer ? . AfterRead ( uniqueEntities , pipeline ) ;
287
+ hookContainer . AfterRead ( uniqueEntities , pipeline ) ;
298
288
}
299
289
EntityTreeLayer nextLayer = _layerFactory . CreateLayer ( layer ) ;
300
290
RecursiveAfterRead ( nextLayer , pipeline ) ;
301
- FlushRegister ( ) ;
302
291
}
303
292
304
293
void RecursiveAfterRead ( EntityTreeLayer currentLayer , ResourceAction pipeline )
@@ -326,10 +315,8 @@ public virtual void AfterCreate<TEntity>(IEnumerable<TEntity> entities, Resource
326
315
}
327
316
EntityTreeLayer nextLayer = _layerFactory . CreateLayer ( layer ) ;
328
317
329
- FlushRegister ( ) ;
330
318
}
331
319
332
-
333
320
public virtual void AfterUpdate < TEntity > ( IEnumerable < TEntity > entities , ResourceAction pipeline ) where TEntity : class , IIdentifiable
334
321
{
335
322
var hookContainer = _meta . GetResourceHookContainer < TEntity > ( ResourceHook . AfterUpdate ) ;
@@ -339,7 +326,6 @@ public virtual void AfterUpdate<TEntity>(IEnumerable<TEntity> entities, Resource
339
326
var uniqueEntities = layer . GetAllUniqueEntities ( ) . Cast < TEntity > ( ) ;
340
327
hookContainer ? . AfterUpdate ( uniqueEntities , pipeline ) ;
341
328
}
342
- FlushRegister ( ) ;
343
329
}
344
330
345
331
void AfterUpdateRelationship ( EntityTreeLayer currentLayer , ResourceAction pipeline )
@@ -363,9 +349,8 @@ public virtual void AfterDelete<TEntity>(IEnumerable<TEntity> entities, Resource
363
349
if ( hookContainer != null )
364
350
{
365
351
var uniqueEntities = layer . GetAllUniqueEntities ( ) . Cast < TEntity > ( ) ;
366
- hookContainer ? . AfterDelete ( uniqueEntities , pipeline , succeeded ) ;
352
+ hookContainer . AfterDelete ( uniqueEntities , pipeline , succeeded ) ;
367
353
}
368
- FlushRegister ( ) ;
369
354
}
370
355
371
356
@@ -429,11 +414,6 @@ IList LoadDbValues(IList entities, List<RelationshipProxy> relationships, Type e
429
414
}
430
415
431
416
432
-
433
-
434
-
435
-
436
-
437
417
/// <summary>
438
418
/// checks that the collection does not contain more than one item when
439
419
/// relevant (eg AfterRead from GetSingle pipeline).
@@ -469,16 +449,6 @@ IEnumerable CallHook(IResourceHookContainer container, ResourceHook hook, object
469
449
return ( IEnumerable ) ThrowJsonApiExceptionOnError ( ( ) => method . Invoke ( container , arguments ) ) ;
470
450
}
471
451
472
- /// <summary>
473
- /// We need to flush the list of processed entities because typically
474
- /// the hook executor will be caled twice per service pipeline (eg BeforeCreate
475
- /// and AfterCreate).
476
- /// </summary>
477
- void FlushRegister ( )
478
- {
479
- _processedEntities = new Dictionary < Type , HashSet < IIdentifiable > > ( ) ;
480
- }
481
-
482
452
object ThrowJsonApiExceptionOnError ( Func < object > action )
483
453
{
484
454
try
0 commit comments