77using JsonApiDotNetCore . Internal . Generics ;
88using JsonApiDotNetCore . Models ;
99using JsonApiDotNetCore . Extensions ;
10- using PrincipalType = System . Type ;
11- using DependentType = System . Type ;
12- using Microsoft . EntityFrameworkCore ;
10+ using LeftType = System . Type ;
11+ using RightType = System . Type ;
1312using JsonApiDotNetCore . Internal ;
14- using JsonApiDotNetCore . Internal . Contracts ;
1513using JsonApiDotNetCore . Configuration ;
1614
1715namespace JsonApiDotNetCore . Hooks
@@ -22,31 +20,31 @@ internal class HookExecutorHelper : IHookExecutorHelper
2220 private readonly IdentifiableComparer _comparer = new IdentifiableComparer ( ) ;
2321 private readonly IJsonApiOptions _options ;
2422 protected readonly IGenericProcessorFactory _genericProcessorFactory ;
25- protected readonly Dictionary < DependentType , IResourceHookContainer > _hookContainers ;
26- protected readonly Dictionary < DependentType , IHooksDiscovery > _hookDiscoveries ;
23+ protected readonly Dictionary < RightType , IResourceHookContainer > _hookContainers ;
24+ protected readonly Dictionary < RightType , IHooksDiscovery > _hookDiscoveries ;
2725 protected readonly List < ResourceHook > _targetedHooksForRelatedEntities ;
2826
2927 public HookExecutorHelper ( IGenericProcessorFactory genericProcessorFactory ,
3028 IJsonApiOptions options )
3129 {
3230 _options = options ;
3331 _genericProcessorFactory = genericProcessorFactory ;
34- _hookContainers = new Dictionary < DependentType , IResourceHookContainer > ( ) ;
35- _hookDiscoveries = new Dictionary < DependentType , IHooksDiscovery > ( ) ;
32+ _hookContainers = new Dictionary < RightType , IResourceHookContainer > ( ) ;
33+ _hookDiscoveries = new Dictionary < RightType , IHooksDiscovery > ( ) ;
3634 _targetedHooksForRelatedEntities = new List < ResourceHook > ( ) ;
3735 }
3836
3937 /// <inheritdoc/>
40- public IResourceHookContainer GetResourceHookContainer ( DependentType dependentType , ResourceHook hook = ResourceHook . None )
38+ public IResourceHookContainer GetResourceHookContainer ( RightType rightType , ResourceHook hook = ResourceHook . None )
4139 {
4240 /// checking the cache if we have a reference for the requested container,
4341 /// regardless of the hook we will use it for. If the value is null,
4442 /// it means there was no implementation IResourceHookContainer at all,
4543 /// so we need not even bother.
46- if ( ! _hookContainers . TryGetValue ( dependentType , out IResourceHookContainer container ) )
44+ if ( ! _hookContainers . TryGetValue ( rightType , out IResourceHookContainer container ) )
4745 {
48- container = ( _genericProcessorFactory . GetProcessor < IResourceHookContainer > ( typeof ( ResourceDefinition < > ) , dependentType ) ) ;
49- _hookContainers [ dependentType ] = container ;
46+ container = ( _genericProcessorFactory . GetProcessor < IResourceHookContainer > ( typeof ( ResourceDefinition < > ) , rightType ) ) ;
47+ _hookContainers [ rightType ] = container ;
5048 }
5149 if ( container == null ) return container ;
5250
@@ -65,7 +63,7 @@ public IResourceHookContainer GetResourceHookContainer(DependentType dependentTy
6563
6664 foreach ( ResourceHook targetHook in targetHooks )
6765 {
68- if ( ShouldExecuteHook ( dependentType , targetHook ) ) return container ;
66+ if ( ShouldExecuteHook ( rightType , targetHook ) ) return container ;
6967 }
7068 return null ;
7169 }
@@ -76,7 +74,7 @@ public IResourceHookContainer<TResource> GetResourceHookContainer<TResource>(Res
7674 return ( IResourceHookContainer < TResource > ) GetResourceHookContainer ( typeof ( TResource ) , hook ) ;
7775 }
7876
79- public IEnumerable LoadDbValues ( PrincipalType entityTypeForRepository , IEnumerable entities , ResourceHook hook , params RelationshipAttribute [ ] inclusionChain )
77+ public IEnumerable LoadDbValues ( LeftType entityTypeForRepository , IEnumerable entities , ResourceHook hook , params RelationshipAttribute [ ] inclusionChain )
8078 {
8179 var idType = TypeHelper . GetIdentifierType ( entityTypeForRepository ) ;
8280 var parameterizedGetWhere = GetType ( )
@@ -107,7 +105,7 @@ public bool ShouldLoadDbValues(Type entityType, ResourceHook hook)
107105 return _options . LoaDatabaseValues ;
108106 }
109107
110- bool ShouldExecuteHook ( DependentType entityType , ResourceHook hook )
108+ bool ShouldExecuteHook ( RightType entityType , ResourceHook hook )
111109 {
112110 var discovery = GetHookDiscovery ( entityType ) ;
113111 return discovery . ImplementedHooks . Contains ( hook ) ;
@@ -145,46 +143,46 @@ IResourceReadRepository<TResource, TId> GetRepository<TResource, TId>() where TR
145143
146144
147145 public Dictionary < RelationshipAttribute , IEnumerable > LoadImplicitlyAffected (
148- Dictionary < RelationshipAttribute , IEnumerable > principalEntitiesByRelation ,
149- IEnumerable existingDependentEntities = null )
146+ Dictionary < RelationshipAttribute , IEnumerable > leftEntitiesByRelation ,
147+ IEnumerable existingRightEntities = null )
150148 {
151149 var implicitlyAffected = new Dictionary < RelationshipAttribute , IEnumerable > ( ) ;
152- foreach ( var kvp in principalEntitiesByRelation )
150+ foreach ( var kvp in leftEntitiesByRelation )
153151 {
154- if ( IsHasManyThrough ( kvp , out var principals , out var relationship ) ) continue ;
152+ if ( IsHasManyThrough ( kvp , out var lefts , out var relationship ) ) continue ;
155153
156154 // note that we dont't have to check if BeforeImplicitUpdate hook is implemented. If not, it wont ever get here.
157- var includedPrincipals = LoadDbValues ( relationship . PrincipalType , principals , ResourceHook . BeforeImplicitUpdateRelationship , relationship ) ;
155+ var includedLefts = LoadDbValues ( relationship . LeftType , lefts , ResourceHook . BeforeImplicitUpdateRelationship , relationship ) ;
158156
159- foreach ( IIdentifiable ip in includedPrincipals )
157+ foreach ( IIdentifiable ip in includedLefts )
160158 {
161- IList dbDependentEntityList = null ;
159+ IList dbRightEntityList = null ;
162160 var relationshipValue = relationship . GetValue ( ip ) ;
163161 if ( ! ( relationshipValue is IEnumerable ) )
164162 {
165- dbDependentEntityList = TypeHelper . CreateListFor ( relationship . DependentType ) ;
166- if ( relationshipValue != null ) dbDependentEntityList . Add ( relationshipValue ) ;
163+ dbRightEntityList = TypeHelper . CreateListFor ( relationship . RightType ) ;
164+ if ( relationshipValue != null ) dbRightEntityList . Add ( relationshipValue ) ;
167165 }
168166 else
169167 {
170- dbDependentEntityList = ( IList ) relationshipValue ;
168+ dbRightEntityList = ( IList ) relationshipValue ;
171169 }
172- var dbDependentEntityListCasted = dbDependentEntityList . Cast < IIdentifiable > ( ) . ToList ( ) ;
173- if ( existingDependentEntities != null ) dbDependentEntityListCasted = dbDependentEntityListCasted . Except ( existingDependentEntities . Cast < IIdentifiable > ( ) , _comparer ) . ToList ( ) ;
170+ var dbRightEntityListCasted = dbRightEntityList . Cast < IIdentifiable > ( ) . ToList ( ) ;
171+ if ( existingRightEntities != null ) dbRightEntityListCasted = dbRightEntityListCasted . Except ( existingRightEntities . Cast < IIdentifiable > ( ) , _comparer ) . ToList ( ) ;
174172
175- if ( dbDependentEntityListCasted . Any ( ) )
173+ if ( dbRightEntityListCasted . Any ( ) )
176174 {
177175 if ( ! implicitlyAffected . TryGetValue ( relationship , out IEnumerable affected ) )
178176 {
179- affected = TypeHelper . CreateListFor ( relationship . DependentType ) ;
177+ affected = TypeHelper . CreateListFor ( relationship . RightType ) ;
180178 implicitlyAffected [ relationship ] = affected ;
181179 }
182- ( ( IList ) affected ) . AddRange ( dbDependentEntityListCasted ) ;
180+ ( ( IList ) affected ) . AddRange ( dbRightEntityListCasted ) ;
183181 }
184182 }
185183 }
186184
187- return implicitlyAffected . ToDictionary ( kvp => kvp . Key , kvp => TypeHelper . CreateHashSetFor ( kvp . Key . DependentType , kvp . Value ) ) ;
185+ return implicitlyAffected . ToDictionary ( kvp => kvp . Key , kvp => TypeHelper . CreateHashSetFor ( kvp . Key . RightType , kvp . Value ) ) ;
188186
189187 }
190188
0 commit comments