Skip to content

Commit 6a186a5

Browse files
committed
style: rename GenericProcessorFactory --> GenericServiceFactory
1 parent 7d235ab commit 6a186a5

File tree

6 files changed

+37
-37
lines changed

6 files changed

+37
-37
lines changed

benchmarks/Serialization/JsonApiSerializer_Benchmarks.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
// jsonApiOptions.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
3535
// jsonApiContextMock.Setup(m => m.Options).Returns(jsonApiOptions);
3636

37-
// var genericProcessorFactoryMock = new Mock<IGenericProcessorFactory>();
37+
// var genericServiceFactoryMock = new Mock<IgenericServiceFactory>();
3838

3939
// var documentBuilder = new BaseDocumentBuilder(jsonApiContextMock.Object);
4040
// _jsonApiSerializer = new JsonApiSerializer(jsonApiContextMock.Object, documentBuilder);

src/JsonApiDotNetCore/Builders/JsonApiApplicationBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void ConfigureServices()
154154
_services.AddScoped<IScopedServiceProvider, RequestScopedServiceProvider>();
155155
_services.AddScoped<IJsonApiWriter, JsonApiWriter>();
156156
_services.AddScoped<IJsonApiReader, JsonApiReader>();
157-
_services.AddScoped<IGenericProcessorFactory, GenericProcessorFactory>();
157+
_services.AddScoped<IGenericServiceFactory, genericServiceFactory>();
158158
_services.AddScoped(typeof(HasManyThroughUpdateHelper<>));
159159
_services.AddScoped<IQueryParameterDiscovery, QueryParameterDiscovery>();
160160
_services.AddScoped<ITargetedFields, TargetedFields>();

src/JsonApiDotNetCore/Data/DefaultResourceRepository.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@ public class DefaultResourceRepository<TResource, TId> : IResourceRepository<TRe
2525
private readonly DbContext _context;
2626
private readonly DbSet<TResource> _dbSet;
2727
private readonly IResourceGraph _resourceGraph;
28-
private readonly IGenericProcessorFactory _genericProcessorFactory;
28+
private readonly IGenericServiceFactory _genericServiceFactory;
2929

3030
public DefaultResourceRepository(
3131
ITargetedFields targetedFields,
3232
IDbContextResolver contextResolver,
3333
IResourceGraph resourceGraph,
34-
IGenericProcessorFactory genericProcessorFactory)
35-
: this(targetedFields, contextResolver, resourceGraph, genericProcessorFactory, null)
34+
IGenericServiceFactory genericServiceFactory)
35+
: this(targetedFields, contextResolver, resourceGraph, genericServiceFactory, null)
3636
{ }
3737

3838
public DefaultResourceRepository(
3939
ITargetedFields targetedFields,
4040
IDbContextResolver contextResolver,
4141
IResourceGraph resourceGraph,
42-
IGenericProcessorFactory genericProcessorFactory,
42+
IGenericServiceFactory genericServiceFactory,
4343
ILoggerFactory loggerFactory = null)
4444
{
4545
_targetedFields = targetedFields;
4646
_resourceGraph = resourceGraph;
47-
_genericProcessorFactory = genericProcessorFactory;
47+
_genericServiceFactory = genericServiceFactory;
4848
_context = contextResolver.GetContext();
4949
_dbSet = _context.Set<TResource>();
5050
}
@@ -258,7 +258,7 @@ public async Task UpdateRelationshipsAsync(object parent, RelationshipAttribute
258258
{
259259
if (relationship is HasManyThroughAttribute hasManyThrough)
260260
{
261-
var helper = _genericProcessorFactory.GetProcessor<IHasManyThroughUpdateHelper>(typeof(HasManyThroughUpdateHelper<>), hasManyThrough.ThroughType);
261+
var helper = _genericServiceFactory.Get<IHasManyThroughUpdateHelper>(typeof(HasManyThroughUpdateHelper<>), hasManyThrough.ThroughType);
262262
await helper.UpdateAsync((IIdentifiable)parent, hasManyThrough, relationshipIds);
263263
return;
264264
}
@@ -424,17 +424,17 @@ public class DefaultResourceRepository<TResource> : DefaultResourceRepository<TR
424424
public DefaultResourceRepository(ITargetedFields targetedFields,
425425
IDbContextResolver contextResolver,
426426
IResourceGraph contextEntityProvider,
427-
IGenericProcessorFactory genericProcessorFactory)
428-
: base(targetedFields, contextResolver, contextEntityProvider, genericProcessorFactory)
427+
IGenericServiceFactory genericServiceFactory)
428+
: base(targetedFields, contextResolver, contextEntityProvider, genericServiceFactory)
429429
{
430430
}
431431

432432
public DefaultResourceRepository(ITargetedFields targetedFields,
433433
IDbContextResolver contextResolver,
434434
IResourceGraph contextEntityProvider,
435-
IGenericProcessorFactory genericProcessorFactory,
435+
IGenericServiceFactory genericServiceFactory,
436436
ILoggerFactory loggerFactory = null)
437-
: base(targetedFields, contextResolver, contextEntityProvider, genericProcessorFactory, loggerFactory)
437+
: base(targetedFields, contextResolver, contextEntityProvider, genericServiceFactory, loggerFactory)
438438
{
439439
}
440440
}

src/JsonApiDotNetCore/Internal/Generics/GenericProcessorFactory.cs renamed to src/JsonApiDotNetCore/Internal/Generics/GenericServiceFactory.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace JsonApiDotNetCore.Internal.Generics
88
/// are not known until runtime. The typical use case would be for
99
/// accessing relationship data or resolving operations processors.
1010
/// </summary>
11-
public interface IGenericProcessorFactory
11+
public interface IGenericServiceFactory
1212
{
1313
/// <summary>
1414
/// Constructs the generic type and locates the service, then casts to TInterface
@@ -18,7 +18,7 @@ public interface IGenericProcessorFactory
1818
/// GetProcessor&lt;IGenericProcessor&gt;(typeof(GenericProcessor&lt;&gt;), typeof(TResource));
1919
/// </code>
2020
/// </example>
21-
TInterface GetProcessor<TInterface>(Type openGenericType, Type resourceType);
21+
TInterface Get<TInterface>(Type openGenericType, Type resourceType);
2222

2323
/// <summary>
2424
/// Constructs the generic type and locates the service, then casts to TInterface
@@ -28,25 +28,25 @@ public interface IGenericProcessorFactory
2828
/// GetProcessor&lt;IGenericProcessor&gt;(typeof(GenericProcessor&lt;,&gt;), typeof(TResource), typeof(TId));
2929
/// </code>
3030
/// </example>
31-
TInterface GetProcessor<TInterface>(Type openGenericType, Type resourceType, Type keyType);
31+
TInterface Get<TInterface>(Type openGenericType, Type resourceType, Type keyType);
3232
}
3333

34-
public class GenericProcessorFactory : IGenericProcessorFactory
34+
public class GenericServiceFactory : IGenericServiceFactory
3535
{
3636
private readonly IServiceProvider _serviceProvider;
3737

38-
public GenericProcessorFactory(IScopedServiceProvider serviceProvider)
38+
public GenericServiceFactory(IScopedServiceProvider serviceProvider)
3939
{
4040
_serviceProvider = serviceProvider;
4141
}
4242

43-
public TInterface GetProcessor<TInterface>(Type openGenericType, Type resourceType)
44-
=> GetProcessorInternal<TInterface>(openGenericType, resourceType);
43+
public TInterface Get<TInterface>(Type openGenericType, Type resourceType)
44+
=> GetInternal<TInterface>(openGenericType, resourceType);
4545

46-
public TInterface GetProcessor<TInterface>(Type openGenericType, Type resourceType, Type keyType)
47-
=> GetProcessorInternal<TInterface>(openGenericType, resourceType, keyType);
46+
public TInterface Get<TInterface>(Type openGenericType, Type resourceType, Type keyType)
47+
=> GetInternal<TInterface>(openGenericType, resourceType, keyType);
4848

49-
private TInterface GetProcessorInternal<TInterface>(Type openGenericType, params Type[] types)
49+
private TInterface GetInternal<TInterface>(Type openGenericType, params Type[] types)
5050
{
5151
var concreteType = openGenericType.MakeGenericType(types);
5252

src/JsonApiDotNetCore/Internal/Generics/HasManyThroughUpdateHelper.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ namespace JsonApiDotNetCore.Internal.Generics
1212
{
1313
/// <summary>
1414
/// A special helper service that gets instantiated for the right-type of a many-to-many relationship and is responsible for
15-
/// processing updates for that relationships
15+
/// processing updates for that relationships.
1616
/// </summary>
1717
public interface IHasManyThroughUpdateHelper
1818
{
19+
/// <summary>
20+
/// Processes updates of has many through relationship.
21+
/// </summary>
1922
Task UpdateAsync(IIdentifiable parent, HasManyThroughAttribute relationship, IEnumerable<string> relationshipIds);
2023
}
2124

22-
/// <summary>
23-
/// A special processor that gets instantiated for a generic type (&lt;T&gt;)
24-
/// when the actual type is not known until runtime. Specifically, this is used for updating
25-
/// relationships.
26-
/// </summary>
25+
/// <inheritdoc/>
2726
public class HasManyThroughUpdateHelper<T> : IHasManyThroughUpdateHelper where T : class
2827
{
2928
private readonly DbContext _context;
@@ -32,6 +31,7 @@ public HasManyThroughUpdateHelper(IDbContextResolver contextResolver)
3231
_context = contextResolver.GetContext();
3332
}
3433

34+
/// <inheritdoc/>
3535
public virtual async Task UpdateAsync(IIdentifiable parent, HasManyThroughAttribute relationship, IEnumerable<string> relationshipIds)
3636
{
3737
// we need to create a transaction for the HasManyThrough case so we can get and remove any existing

test/UnitTests/ResourceHooks/ResourceHooksTestsSetup.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ protected List<TodoItem> CreateTodoWithOwner()
141141

142142
public class HooksTestsSetup : HooksDummyData
143143
{
144-
(Mock<ITargetedFields>, Mock<IIncludeService>, Mock<IGenericProcessorFactory>, IJsonApiOptions) CreateMocks()
144+
(Mock<ITargetedFields>, Mock<IIncludeService>, Mock<IGenericServiceFactory>, IJsonApiOptions) CreateMocks()
145145
{
146-
var pfMock = new Mock<IGenericProcessorFactory>();
146+
var pfMock = new Mock<IGenericServiceFactory>();
147147
var ufMock = new Mock<ITargetedFields>();
148148
var iqsMock = new Mock<IIncludeService>();
149149
var optionsMock = new JsonApiOptions { LoaDatabaseValues = false };
@@ -156,7 +156,7 @@ public class HooksTestsSetup : HooksDummyData
156156
// creates the resource definition mock and corresponding ImplementedHooks discovery instance
157157
var mainResource = CreateResourceDefinition(mainDiscovery);
158158

159-
// mocking the GenericProcessorFactory and JsonApiContext and wiring them up.
159+
// mocking the genericServiceFactory and JsonApiContext and wiring them up.
160160
var (ufMock, iqMock, gpfMock, options) = CreateMocks();
161161

162162
SetupProcessorFactoryForResourceDefinition(gpfMock, mainResource.Object, mainDiscovery, null);
@@ -181,7 +181,7 @@ public class HooksTestsSetup : HooksDummyData
181181
var mainResource = CreateResourceDefinition(mainDiscovery);
182182
var nestedResource = CreateResourceDefinition(nestedDiscovery);
183183

184-
// mocking the GenericProcessorFactory and JsonApiContext and wiring them up.
184+
// mocking the genericServiceFactory and JsonApiContext and wiring them up.
185185
var (ufMock, iqMock, gpfMock, options) = CreateMocks();
186186

187187
var dbContext = repoDbContextOptions != null ? new AppDbContext(repoDbContextOptions) : null;
@@ -212,7 +212,7 @@ public class HooksTestsSetup : HooksDummyData
212212
var firstNestedResource = CreateResourceDefinition(firstNestedDiscovery);
213213
var secondNestedResource = CreateResourceDefinition(secondNestedDiscovery);
214214

215-
// mocking the GenericProcessorFactory and JsonApiContext and wiring them up.
215+
// mocking the genericServiceFactory and JsonApiContext and wiring them up.
216216
var (ufMock, iqMock, gpfMock, options) = CreateMocks();
217217

218218
var dbContext = repoDbContextOptions != null ? new AppDbContext(repoDbContextOptions) : null;
@@ -311,17 +311,17 @@ void MockHooks<TModel>(Mock<IResourceHookContainer<TModel>> resourceDefinition)
311311
}
312312

313313
void SetupProcessorFactoryForResourceDefinition<TModel>(
314-
Mock<IGenericProcessorFactory> processorFactory,
314+
Mock<IGenericServiceFactory> processorFactory,
315315
IResourceHookContainer<TModel> modelResource,
316316
IHooksDiscovery<TModel> discovery,
317317
AppDbContext dbContext = null
318318
)
319319
where TModel : class, IIdentifiable<int>
320320
{
321-
processorFactory.Setup(c => c.GetProcessor<IResourceHookContainer>(typeof(ResourceDefinition<>), typeof(TModel)))
321+
processorFactory.Setup(c => c.Gett<<IResourceHookContainer>(typeof(ResourceDefinition<>), typeof(TModel)))
322322
.Returns(modelResource);
323323

324-
processorFactory.Setup(c => c.GetProcessor<IHooksDiscovery>(typeof(IHooksDiscovery<>), typeof(TModel)))
324+
processorFactory.Setup(c => c.Gett<<IHooksDiscovery>(typeof(IHooksDiscovery<>), typeof(TModel)))
325325
.Returns(discovery);
326326

327327
if (dbContext != null)
@@ -330,7 +330,7 @@ void SetupProcessorFactoryForResourceDefinition<TModel>(
330330
if (idType == typeof(int))
331331
{
332332
IResourceReadRepository<TModel, int> repo = CreateTestRepository<TModel>(dbContext);
333-
processorFactory.Setup(c => c.GetProcessor<IResourceReadRepository<TModel, int>>(typeof(IResourceReadRepository<,>), typeof(TModel), typeof(int))).Returns(repo);
333+
processorFactory.Setup(c => c.Gett<<IResourceReadRepository<TModel, int>>(typeof(IResourceReadRepository<,>), typeof(TModel), typeof(int))).Returns(repo);
334334
}
335335
else
336336
{

0 commit comments

Comments
 (0)