@@ -26,7 +26,7 @@ public ResourceRepositoryAccessor(IServiceProvider serviceProvider, IResourceCon
26
26
public async Task < IReadOnlyCollection < TResource > > GetAsync < TResource > ( QueryLayer layer , CancellationToken cancellationToken )
27
27
where TResource : class , IIdentifiable
28
28
{
29
- dynamic repository = GetReadRepository ( typeof ( TResource ) ) ;
29
+ dynamic repository = ResolveReadRepository ( typeof ( TResource ) ) ;
30
30
return ( IReadOnlyCollection < TResource > ) await repository . GetAsync ( layer , cancellationToken ) ;
31
31
}
32
32
@@ -35,83 +35,83 @@ public async Task<IReadOnlyCollection<IIdentifiable>> GetAsync(Type resourceType
35
35
{
36
36
if ( resourceType == null ) throw new ArgumentNullException ( nameof ( resourceType ) ) ;
37
37
38
- dynamic repository = GetReadRepository ( resourceType ) ;
38
+ dynamic repository = ResolveReadRepository ( resourceType ) ;
39
39
return ( IReadOnlyCollection < IIdentifiable > ) await repository . GetAsync ( layer , cancellationToken ) ;
40
40
}
41
41
42
42
/// <inheritdoc />
43
43
public async Task < int > CountAsync < TResource > ( FilterExpression topFilter , CancellationToken cancellationToken )
44
44
where TResource : class , IIdentifiable
45
45
{
46
- dynamic repository = GetReadRepository ( typeof ( TResource ) ) ;
46
+ dynamic repository = ResolveReadRepository ( typeof ( TResource ) ) ;
47
47
return ( int ) await repository . CountAsync ( topFilter , cancellationToken ) ;
48
48
}
49
49
50
50
/// <inheritdoc />
51
51
public async Task < TResource > GetForCreateAsync < TResource , TId > ( TId id , CancellationToken cancellationToken )
52
52
where TResource : class , IIdentifiable < TId >
53
53
{
54
- dynamic repository = GetWriteRepository ( typeof ( TResource ) ) ;
54
+ dynamic repository = ResolveWriteRepository ( typeof ( TResource ) ) ;
55
55
return await repository . GetForCreateAsync ( id , cancellationToken ) ;
56
56
}
57
57
58
58
/// <inheritdoc />
59
59
public async Task CreateAsync < TResource > ( TResource resourceFromRequest , TResource resourceForDatabase , CancellationToken cancellationToken )
60
60
where TResource : class , IIdentifiable
61
61
{
62
- dynamic repository = GetWriteRepository ( typeof ( TResource ) ) ;
62
+ dynamic repository = ResolveWriteRepository ( typeof ( TResource ) ) ;
63
63
await repository . CreateAsync ( resourceFromRequest , resourceForDatabase , cancellationToken ) ;
64
64
}
65
65
66
66
/// <inheritdoc />
67
67
public async Task < TResource > GetForUpdateAsync < TResource > ( QueryLayer queryLayer , CancellationToken cancellationToken )
68
68
where TResource : class , IIdentifiable
69
69
{
70
- dynamic repository = GetWriteRepository ( typeof ( TResource ) ) ;
70
+ dynamic repository = ResolveWriteRepository ( typeof ( TResource ) ) ;
71
71
return await repository . GetForUpdateAsync ( queryLayer , cancellationToken ) ;
72
72
}
73
73
74
74
/// <inheritdoc />
75
75
public async Task UpdateAsync < TResource > ( TResource resourceFromRequest , TResource resourceFromDatabase , CancellationToken cancellationToken )
76
76
where TResource : class , IIdentifiable
77
77
{
78
- dynamic repository = GetWriteRepository ( typeof ( TResource ) ) ;
78
+ dynamic repository = ResolveWriteRepository ( typeof ( TResource ) ) ;
79
79
await repository . UpdateAsync ( resourceFromRequest , resourceFromDatabase , cancellationToken ) ;
80
80
}
81
81
82
82
/// <inheritdoc />
83
83
public async Task DeleteAsync < TResource , TId > ( TId id , CancellationToken cancellationToken )
84
84
where TResource : class , IIdentifiable < TId >
85
85
{
86
- dynamic repository = GetWriteRepository ( typeof ( TResource ) ) ;
86
+ dynamic repository = ResolveWriteRepository ( typeof ( TResource ) ) ;
87
87
await repository . DeleteAsync ( id , cancellationToken ) ;
88
88
}
89
89
90
90
/// <inheritdoc />
91
91
public async Task SetRelationshipAsync < TResource > ( TResource primaryResource , object secondaryResourceIds , CancellationToken cancellationToken )
92
92
where TResource : class , IIdentifiable
93
93
{
94
- dynamic repository = GetWriteRepository ( typeof ( TResource ) ) ;
94
+ dynamic repository = ResolveWriteRepository ( typeof ( TResource ) ) ;
95
95
await repository . SetRelationshipAsync ( primaryResource , secondaryResourceIds , cancellationToken ) ;
96
96
}
97
97
98
98
/// <inheritdoc />
99
99
public async Task AddToToManyRelationshipAsync < TResource , TId > ( TId primaryId , ISet < IIdentifiable > secondaryResourceIds , CancellationToken cancellationToken )
100
100
where TResource : class , IIdentifiable < TId >
101
101
{
102
- dynamic repository = GetWriteRepository ( typeof ( TResource ) ) ;
102
+ dynamic repository = ResolveWriteRepository ( typeof ( TResource ) ) ;
103
103
await repository . AddToToManyRelationshipAsync ( primaryId , secondaryResourceIds , cancellationToken ) ;
104
104
}
105
105
106
106
/// <inheritdoc />
107
107
public async Task RemoveFromToManyRelationshipAsync < TResource > ( TResource primaryResource , ISet < IIdentifiable > secondaryResourceIds , CancellationToken cancellationToken )
108
108
where TResource : class , IIdentifiable
109
109
{
110
- dynamic repository = GetWriteRepository ( typeof ( TResource ) ) ;
110
+ dynamic repository = ResolveWriteRepository ( typeof ( TResource ) ) ;
111
111
await repository . RemoveFromToManyRelationshipAsync ( primaryResource , secondaryResourceIds , cancellationToken ) ;
112
112
}
113
113
114
- protected object GetReadRepository ( Type resourceType )
114
+ protected virtual object ResolveReadRepository ( Type resourceType )
115
115
{
116
116
var resourceContext = _resourceContextProvider . GetResourceContext ( resourceType ) ;
117
117
@@ -130,7 +130,7 @@ protected object GetReadRepository(Type resourceType)
130
130
return _serviceProvider . GetRequiredService ( resourceDefinitionType ) ;
131
131
}
132
132
133
- protected object GetWriteRepository ( Type resourceType )
133
+ protected virtual object ResolveWriteRepository ( Type resourceType )
134
134
{
135
135
var resourceContext = _resourceContextProvider . GetResourceContext ( resourceType ) ;
136
136
0 commit comments