@@ -47,8 +47,6 @@ IResourceGraph graph
47
47
_layerFactory = new EntityTreeLayerFactory ( meta , graph , _context ) ;
48
48
}
49
49
50
-
51
-
52
50
public virtual void BeforeRead < TEntity > ( ResourceAction pipeline , string stringId = null ) where TEntity : class , IIdentifiable
53
51
{
54
52
var hookContainer = _meta . GetResourceHookContainer < TEntity > ( ResourceHook . BeforeRead ) ;
@@ -227,6 +225,7 @@ public virtual IEnumerable<TEntity> OnReturn<TEntity>(IEnumerable<TEntity> entit
227
225
/// this is not updating unique entities internally!!!! say [a_1, a_2] => [a_1],
228
226
/// then nested hooks for relations of a_2 are still being fired
229
227
entities = entities . Intersect ( filteredUniqueEntities , Comparer ) . Cast < TEntity > ( ) ;
228
+ ValidateHookResponse ( entities ) ;
230
229
}
231
230
var nextLayer = _layerFactory . CreateLayer ( layer ) ;
232
231
RecursiveOnReturn ( nextLayer , pipeline ) ;
@@ -311,7 +310,7 @@ public virtual void AfterCreate<TEntity>(IEnumerable<TEntity> entities, Resource
311
310
if ( hookContainer != null )
312
311
{
313
312
var uniqueEntities = layer . GetAllUniqueEntities ( ) . Cast < TEntity > ( ) ;
314
- hookContainer ? . AfterCreate ( uniqueEntities , pipeline ) ;
313
+ hookContainer . AfterCreate ( uniqueEntities , pipeline ) ;
315
314
}
316
315
EntityTreeLayer nextLayer = _layerFactory . CreateLayer ( layer ) ;
317
316
@@ -324,7 +323,7 @@ public virtual void AfterUpdate<TEntity>(IEnumerable<TEntity> entities, Resource
324
323
if ( hookContainer != null )
325
324
{
326
325
var uniqueEntities = layer . GetAllUniqueEntities ( ) . Cast < TEntity > ( ) ;
327
- hookContainer ? . AfterUpdate ( uniqueEntities , pipeline ) ;
326
+ hookContainer . AfterUpdate ( uniqueEntities , pipeline ) ;
328
327
}
329
328
}
330
329
@@ -420,12 +419,12 @@ IList LoadDbValues(IList entities, List<RelationshipProxy> relationships, Type e
420
419
/// </summary>
421
420
/// <param name="returnedList"> The collection returned from the hook</param>
422
421
/// <param name="pipeline">The pipeine from which the hook was fired</param>
423
- protected void ValidateHookResponse ( object returnedList , ResourceAction pipeline = 0 )
422
+ void ValidateHookResponse < T > ( IEnumerable < T > returnedList , ResourceAction pipeline = 0 )
424
423
{
425
- if ( pipeline != ResourceAction . None && SingleActions . Contains ( pipeline ) && ( ( IEnumerable ) returnedList ) . Cast < object > ( ) . Count ( ) > 1 )
424
+ if ( pipeline == ResourceAction . GetSingle && returnedList . Count ( ) > 1 )
426
425
{
427
- throw new ApplicationException ( "The returned collection from this hook may only contain one item in the case of the" +
428
- pipeline . ToString ( ) + "pipeline" ) ;
426
+ throw new ApplicationException ( "The returned collection from this hook may contain at most one item in the case of the" +
427
+ pipeline . ToString ( "G" ) + "pipeline" ) ;
429
428
}
430
429
}
431
430
0 commit comments