7
7
using JsonApiDotNetCore . Internal . Generics ;
8
8
using JsonApiDotNetCore . Models ;
9
9
using 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 ;
13
12
using JsonApiDotNetCore . Internal ;
14
- using JsonApiDotNetCore . Internal . Contracts ;
15
13
using JsonApiDotNetCore . Configuration ;
16
14
17
15
namespace JsonApiDotNetCore . Hooks
@@ -22,31 +20,31 @@ internal class HookExecutorHelper : IHookExecutorHelper
22
20
private readonly IdentifiableComparer _comparer = new IdentifiableComparer ( ) ;
23
21
private readonly IJsonApiOptions _options ;
24
22
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 ;
27
25
protected readonly List < ResourceHook > _targetedHooksForRelatedEntities ;
28
26
29
27
public HookExecutorHelper ( IGenericProcessorFactory genericProcessorFactory ,
30
28
IJsonApiOptions options )
31
29
{
32
30
_options = options ;
33
31
_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 > ( ) ;
36
34
_targetedHooksForRelatedEntities = new List < ResourceHook > ( ) ;
37
35
}
38
36
39
37
/// <inheritdoc/>
40
- public IResourceHookContainer GetResourceHookContainer ( DependentType dependentType , ResourceHook hook = ResourceHook . None )
38
+ public IResourceHookContainer GetResourceHookContainer ( RightType rightType , ResourceHook hook = ResourceHook . None )
41
39
{
42
40
/// checking the cache if we have a reference for the requested container,
43
41
/// regardless of the hook we will use it for. If the value is null,
44
42
/// it means there was no implementation IResourceHookContainer at all,
45
43
/// so we need not even bother.
46
- if ( ! _hookContainers . TryGetValue ( dependentType , out IResourceHookContainer container ) )
44
+ if ( ! _hookContainers . TryGetValue ( rightType , out IResourceHookContainer container ) )
47
45
{
48
- container = ( _genericProcessorFactory . GetProcessor < IResourceHookContainer > ( typeof ( ResourceDefinition < > ) , dependentType ) ) ;
49
- _hookContainers [ dependentType ] = container ;
46
+ container = ( _genericProcessorFactory . GetProcessor < IResourceHookContainer > ( typeof ( ResourceDefinition < > ) , rightType ) ) ;
47
+ _hookContainers [ rightType ] = container ;
50
48
}
51
49
if ( container == null ) return container ;
52
50
@@ -65,7 +63,7 @@ public IResourceHookContainer GetResourceHookContainer(DependentType dependentTy
65
63
66
64
foreach ( ResourceHook targetHook in targetHooks )
67
65
{
68
- if ( ShouldExecuteHook ( dependentType , targetHook ) ) return container ;
66
+ if ( ShouldExecuteHook ( rightType , targetHook ) ) return container ;
69
67
}
70
68
return null ;
71
69
}
@@ -76,7 +74,7 @@ public IResourceHookContainer<TResource> GetResourceHookContainer<TResource>(Res
76
74
return ( IResourceHookContainer < TResource > ) GetResourceHookContainer ( typeof ( TResource ) , hook ) ;
77
75
}
78
76
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 )
80
78
{
81
79
var idType = TypeHelper . GetIdentifierType ( entityTypeForRepository ) ;
82
80
var parameterizedGetWhere = GetType ( )
@@ -107,7 +105,7 @@ public bool ShouldLoadDbValues(Type entityType, ResourceHook hook)
107
105
return _options . LoaDatabaseValues ;
108
106
}
109
107
110
- bool ShouldExecuteHook ( DependentType entityType , ResourceHook hook )
108
+ bool ShouldExecuteHook ( RightType entityType , ResourceHook hook )
111
109
{
112
110
var discovery = GetHookDiscovery ( entityType ) ;
113
111
return discovery . ImplementedHooks . Contains ( hook ) ;
@@ -145,46 +143,46 @@ IResourceReadRepository<TResource, TId> GetRepository<TResource, TId>() where TR
145
143
146
144
147
145
public Dictionary < RelationshipAttribute , IEnumerable > LoadImplicitlyAffected (
148
- Dictionary < RelationshipAttribute , IEnumerable > principalEntitiesByRelation ,
149
- IEnumerable existingDependentEntities = null )
146
+ Dictionary < RelationshipAttribute , IEnumerable > leftEntitiesByRelation ,
147
+ IEnumerable existingRightEntities = null )
150
148
{
151
149
var implicitlyAffected = new Dictionary < RelationshipAttribute , IEnumerable > ( ) ;
152
- foreach ( var kvp in principalEntitiesByRelation )
150
+ foreach ( var kvp in leftEntitiesByRelation )
153
151
{
154
- if ( IsHasManyThrough ( kvp , out var principals , out var relationship ) ) continue ;
152
+ if ( IsHasManyThrough ( kvp , out var lefts , out var relationship ) ) continue ;
155
153
156
154
// 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 ) ;
158
156
159
- foreach ( IIdentifiable ip in includedPrincipals )
157
+ foreach ( IIdentifiable ip in includedLefts )
160
158
{
161
- IList dbDependentEntityList = null ;
159
+ IList dbRightEntityList = null ;
162
160
var relationshipValue = relationship . GetValue ( ip ) ;
163
161
if ( ! ( relationshipValue is IEnumerable ) )
164
162
{
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 ) ;
167
165
}
168
166
else
169
167
{
170
- dbDependentEntityList = ( IList ) relationshipValue ;
168
+ dbRightEntityList = ( IList ) relationshipValue ;
171
169
}
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 ( ) ;
174
172
175
- if ( dbDependentEntityListCasted . Any ( ) )
173
+ if ( dbRightEntityListCasted . Any ( ) )
176
174
{
177
175
if ( ! implicitlyAffected . TryGetValue ( relationship , out IEnumerable affected ) )
178
176
{
179
- affected = TypeHelper . CreateListFor ( relationship . DependentType ) ;
177
+ affected = TypeHelper . CreateListFor ( relationship . RightType ) ;
180
178
implicitlyAffected [ relationship ] = affected ;
181
179
}
182
- ( ( IList ) affected ) . AddRange ( dbDependentEntityListCasted ) ;
180
+ ( ( IList ) affected ) . AddRange ( dbRightEntityListCasted ) ;
183
181
}
184
182
}
185
183
}
186
184
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 ) ) ;
188
186
189
187
}
190
188
0 commit comments