Skip to content

Commit 833da6a

Browse files
committed
style: DefaultResourceRepository and DefaultEntityService as consistent class names, with equivalent interfaces
1 parent 2302fcb commit 833da6a

20 files changed

+100
-119
lines changed

src/Examples/JsonApiDotNetCoreExample/Services/CustomArticleService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
namespace JsonApiDotNetCoreExample.Services
1313
{
14-
public class CustomArticleService : EntityResourceService<Article>
14+
public class CustomArticleService : DefaultResourceService<Article>
1515
{
1616
public CustomArticleService(ISortService sortService,
1717
IFilterService filterService,
18-
IEntityRepository<Article, int> repository,
18+
IResourceRepository<Article, int> repository,
1919
IJsonApiOptions options,
2020
IIncludeService includeService,
2121
ISparseFieldsService sparseFieldsService,

src/JsonApiDotNetCore/Builders/JsonApiApplicationBuilder.cs

+19-19
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void ConfigureMvc()
7373

7474
var routingConvention = intermediateProvider.GetRequiredService<IJsonApiRoutingConvention>();
7575
_mvcBuilder.AddMvcOptions(opt => opt.Conventions.Insert(0, routingConvention));
76-
_services.AddSingleton<IControllerResourceMapping>(routingConvention);
76+
_services.AddSingleton<IControllerResourceMapping>(routingConvention);
7777
}
7878

7979
/// <summary>
@@ -118,32 +118,32 @@ public void ConfigureServices()
118118
_services.AddSingleton(new DbContextOptionsBuilder().Options);
119119
}
120120

121-
_services.AddScoped(typeof(IEntityRepository<>), typeof(DefaultEntityRepository<>));
122-
_services.AddScoped(typeof(IEntityRepository<,>), typeof(DefaultEntityRepository<,>));
121+
_services.AddScoped(typeof(IResourceRepository<>), typeof(DefaultResourceRepository<>));
122+
_services.AddScoped(typeof(IResourceRepository<,>), typeof(DefaultResourceRepository<,>));
123123

124-
_services.AddScoped(typeof(IEntityReadRepository<,>), typeof(DefaultEntityRepository<,>));
125-
_services.AddScoped(typeof(IEntityWriteRepository<,>), typeof(DefaultEntityRepository<,>));
124+
_services.AddScoped(typeof(IResourceReadRepository<,>), typeof(DefaultResourceRepository<,>));
125+
_services.AddScoped(typeof(IResourceWriteRepository<,>), typeof(DefaultResourceRepository<,>));
126126

127-
_services.AddScoped(typeof(ICreateService<>), typeof(EntityResourceService<>));
128-
_services.AddScoped(typeof(ICreateService<,>), typeof(EntityResourceService<,>));
127+
_services.AddScoped(typeof(ICreateService<>), typeof(DefaultResourceService<>));
128+
_services.AddScoped(typeof(ICreateService<,>), typeof(DefaultResourceService<,>));
129129

130-
_services.AddScoped(typeof(IGetAllService<>), typeof(EntityResourceService<>));
131-
_services.AddScoped(typeof(IGetAllService<,>), typeof(EntityResourceService<,>));
130+
_services.AddScoped(typeof(IGetAllService<>), typeof(DefaultResourceService<>));
131+
_services.AddScoped(typeof(IGetAllService<,>), typeof(DefaultResourceService<,>));
132132

133-
_services.AddScoped(typeof(IGetByIdService<>), typeof(EntityResourceService<>));
134-
_services.AddScoped(typeof(IGetByIdService<,>), typeof(EntityResourceService<,>));
133+
_services.AddScoped(typeof(IGetByIdService<>), typeof(DefaultResourceService<>));
134+
_services.AddScoped(typeof(IGetByIdService<,>), typeof(DefaultResourceService<,>));
135135

136-
_services.AddScoped(typeof(IGetRelationshipService<,>), typeof(EntityResourceService<>));
137-
_services.AddScoped(typeof(IGetRelationshipService<,>), typeof(EntityResourceService<,>));
136+
_services.AddScoped(typeof(IGetRelationshipService<,>), typeof(DefaultResourceService<>));
137+
_services.AddScoped(typeof(IGetRelationshipService<,>), typeof(DefaultResourceService<,>));
138138

139-
_services.AddScoped(typeof(IUpdateService<>), typeof(EntityResourceService<>));
140-
_services.AddScoped(typeof(IUpdateService<,>), typeof(EntityResourceService<,>));
139+
_services.AddScoped(typeof(IUpdateService<>), typeof(DefaultResourceService<>));
140+
_services.AddScoped(typeof(IUpdateService<,>), typeof(DefaultResourceService<,>));
141141

142-
_services.AddScoped(typeof(IDeleteService<>), typeof(EntityResourceService<>));
143-
_services.AddScoped(typeof(IDeleteService<,>), typeof(EntityResourceService<,>));
142+
_services.AddScoped(typeof(IDeleteService<>), typeof(DefaultResourceService<>));
143+
_services.AddScoped(typeof(IDeleteService<,>), typeof(DefaultResourceService<,>));
144144

145-
_services.AddScoped(typeof(IResourceService<>), typeof(EntityResourceService<>));
146-
_services.AddScoped(typeof(IResourceService<,>), typeof(EntityResourceService<,>));
145+
_services.AddScoped(typeof(IResourceService<>), typeof(DefaultResourceService<>));
146+
_services.AddScoped(typeof(IResourceService<,>), typeof(DefaultResourceService<,>));
147147

148148
_services.AddSingleton<ILinksConfiguration>(JsonApiOptions);
149149
_services.AddSingleton(resourceGraph);

src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs

+2-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using JsonApiDotNetCore.Configuration;
55
using JsonApiDotNetCore.Extensions;
66
using JsonApiDotNetCore.Internal;
7-
using JsonApiDotNetCore.Internal.Contracts;
87
using JsonApiDotNetCore.Models;
98
using JsonApiDotNetCore.Services;
109
using Microsoft.AspNetCore.Mvc;
@@ -32,14 +31,11 @@ public BaseJsonApiController(
3231
IResourceService<T, TId> resourceService,
3332
ILoggerFactory loggerFactory)
3433
{
35-
if(loggerFactory != null)
36-
{
34+
if (loggerFactory != null)
3735
_logger = loggerFactory.CreateLogger<BaseJsonApiController<T, TId>>();
38-
}
3936
else
40-
{
4137
_logger = new Logger<BaseJsonApiController<T, TId>>(new LoggerFactory());
42-
}
38+
4339
_jsonApiOptions = jsonApiOptions;
4440
_getAll = resourceService;
4541
_getById = resourceService;
@@ -51,7 +47,6 @@ public BaseJsonApiController(
5147
_delete = resourceService;
5248
}
5349

54-
5550
public BaseJsonApiController(
5651
IJsonApiOptions jsonApiOptions,
5752
IResourceQueryService<T, TId> queryService = null,
@@ -68,11 +63,7 @@ public BaseJsonApiController(
6863
_delete = cmdService;
6964
}
7065

71-
/// <summary>
72-
/// Base constructor
73-
/// </summary>
7466
/// <param name="jsonApiOptions"></param>
75-
/// <param name="resourceGraph"></param>
7667
/// <param name="getAll"></param>
7768
/// <param name="getById"></param>
7869
/// <param name="getRelationship"></param>

src/JsonApiDotNetCore/Controllers/JsonApiController.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System.Collections.Generic;
21
using System.Threading.Tasks;
32
using JsonApiDotNetCore.Configuration;
4-
using JsonApiDotNetCore.Internal.Contracts;
53
using JsonApiDotNetCore.Models;
64
using JsonApiDotNetCore.Services;
75
using Microsoft.AspNetCore.Mvc;
@@ -11,11 +9,8 @@ namespace JsonApiDotNetCore.Controllers
119
{
1210
public class JsonApiController<T, TId> : BaseJsonApiController<T, TId> where T : class, IIdentifiable<TId>
1311
{
14-
/// <summary>
15-
///
16-
/// </summary>
12+
1713
/// <param name="jsonApiOptions"></param>
18-
/// <param name="resourceGraph"></param>
1914
/// <param name="resourceService"></param>
2015
/// <param name="loggerFactory"></param>
2116
public JsonApiController(

src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs renamed to src/JsonApiDotNetCore/Data/DefaultResourceRepository.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace JsonApiDotNetCore.Data
1818
/// Provides a default repository implementation and is responsible for
1919
/// abstracting any EF Core APIs away from the service layer.
2020
/// </summary>
21-
public class DefaultEntityRepository<TEntity, TId> : IEntityRepository<TEntity, TId>
21+
public class DefaultResourceRepository<TEntity, TId> : IResourceRepository<TEntity, TId>
2222
where TEntity : class, IIdentifiable<TId>
2323
{
2424
private readonly ITargetedFields _targetedFields;
@@ -27,15 +27,15 @@ public class DefaultEntityRepository<TEntity, TId> : IEntityRepository<TEntity,
2727
private readonly IResourceGraph _resourceGraph;
2828
private readonly IGenericProcessorFactory _genericProcessorFactory;
2929

30-
public DefaultEntityRepository(
30+
public DefaultResourceRepository(
3131
ITargetedFields targetedFields,
3232
IDbContextResolver contextResolver,
3333
IResourceGraph resourceGraph,
3434
IGenericProcessorFactory genericProcessorFactory)
3535
: this(targetedFields, contextResolver, resourceGraph, genericProcessorFactory, null)
3636
{ }
3737

38-
public DefaultEntityRepository(
38+
public DefaultResourceRepository(
3939
ITargetedFields targetedFields,
4040
IDbContextResolver contextResolver,
4141
IResourceGraph resourceGraph,
@@ -414,18 +414,18 @@ private IIdentifiable AttachOrGetTracked(IIdentifiable relationshipValue)
414414
}
415415

416416
/// <inheritdoc />
417-
public class DefaultEntityRepository<TEntity> : DefaultEntityRepository<TEntity, int>, IEntityRepository<TEntity>
417+
public class DefaultResourceRepository<TEntity> : DefaultResourceRepository<TEntity, int>, IResourceRepository<TEntity>
418418
where TEntity : class, IIdentifiable<int>
419419
{
420-
public DefaultEntityRepository(ITargetedFields targetedFields,
420+
public DefaultResourceRepository(ITargetedFields targetedFields,
421421
IDbContextResolver contextResolver,
422422
IResourceGraph contextEntityProvider,
423423
IGenericProcessorFactory genericProcessorFactory)
424424
: base(targetedFields, contextResolver, contextEntityProvider, genericProcessorFactory)
425425
{
426426
}
427427

428-
public DefaultEntityRepository(ITargetedFields targetedFields,
428+
public DefaultResourceRepository(ITargetedFields targetedFields,
429429
IDbContextResolver contextResolver,
430430
IResourceGraph contextEntityProvider,
431431
IGenericProcessorFactory genericProcessorFactory,

src/JsonApiDotNetCore/Data/IEntityRepository.cs

-18
This file was deleted.

src/JsonApiDotNetCore/Data/IEntityReadRepository.cs renamed to src/JsonApiDotNetCore/Data/IResourceReadRepository.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.Linq;
43
using System.Threading.Tasks;
@@ -7,12 +6,12 @@
76

87
namespace JsonApiDotNetCore.Data
98
{
10-
public interface IEntityReadRepository<TEntity>
11-
: IEntityReadRepository<TEntity, int>
9+
public interface IResourceReadRepository<TEntity>
10+
: IResourceReadRepository<TEntity, int>
1211
where TEntity : class, IIdentifiable<int>
1312
{ }
1413

15-
public interface IEntityReadRepository<TEntity, in TId>
14+
public interface IResourceReadRepository<TEntity, in TId>
1615
where TEntity : class, IIdentifiable<TId>
1716
{
1817
/// <summary>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using JsonApiDotNetCore.Models;
2+
3+
namespace JsonApiDotNetCore.Data
4+
{
5+
public interface IResourceRepository<TEntity>
6+
: IResourceRepository<TEntity, int>
7+
where TEntity : class, IIdentifiable<int>
8+
{ }
9+
10+
public interface IResourceRepository<TEntity, in TId>
11+
: IResourceReadRepository<TEntity, TId>,
12+
IResourceWriteRepository<TEntity, TId>
13+
where TEntity : class, IIdentifiable<TId>
14+
{ }
15+
}

src/JsonApiDotNetCore/Data/IEntityWriteRepository.cs renamed to src/JsonApiDotNetCore/Data/IResourceWriteRepository.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
namespace JsonApiDotNetCore.Data
77
{
8-
public interface IEntityWriteRepository<TEntity>
9-
: IEntityWriteRepository<TEntity, int>
8+
public interface IResourceWriteRepository<TEntity>
9+
: IResourceWriteRepository<TEntity, int>
1010
where TEntity : class, IIdentifiable<int>
1111
{ }
1212

13-
public interface IEntityWriteRepository<TEntity, in TId>
13+
public interface IResourceWriteRepository<TEntity, in TId>
1414
where TEntity : class, IIdentifiable<TId>
1515
{
1616
Task<TEntity> CreateAsync(TEntity entity);

src/JsonApiDotNetCore/Graph/ServiceDiscoveryFacade.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public class ServiceDiscoveryFacade : IServiceDiscoveryFacade
4141
};
4242

4343
internal static HashSet<Type> RepositoryInterfaces = new HashSet<Type> {
44-
typeof(IEntityRepository<>),
45-
typeof(IEntityRepository<,>),
44+
typeof(IResourceRepository<>),
45+
typeof(IResourceRepository<,>),
4646
typeof(IEntityWriteRepository<>),
47-
typeof(IEntityWriteRepository<,>),
47+
typeof(IResourceWriteRepository<,>),
4848
typeof(IEntityReadRepository<>),
49-
typeof(IEntityReadRepository<,>)
49+
typeof(IResourceReadRepository<,>)
5050
};
5151
private readonly IServiceCollection _services;
5252
private readonly IResourceGraphBuilder _resourceGraphBuilder;
@@ -173,7 +173,7 @@ private void AddServices(Assembly assembly, ResourceDescriptor resourceDescripto
173173
}
174174

175175
/// <summary>
176-
/// Add <see cref="IEntityRepository{T, TId}"/> implementations to container.
176+
/// Add <see cref="IResourceRepository{T, TId}"/> implementations to container.
177177
/// </summary>
178178
/// <param name="assembly">The assembly to search for resources in.</param>
179179
public ServiceDiscoveryFacade AddRepositories(Assembly assembly)

src/JsonApiDotNetCore/Hooks/Execution/HookExecutorHelper.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ IEnumerable<TEntity> GetWhereAndInclude<TEntity, TId>(IEnumerable<TId> ids, Rela
147147
return repo.Include(query, inclusionChain).ToList();
148148
}
149149

150-
IEntityReadRepository<TEntity, TId> GetRepository<TEntity, TId>() where TEntity : class, IIdentifiable<TId>
150+
IResourceReadRepository<TEntity, TId> GetRepository<TEntity, TId>() where TEntity : class, IIdentifiable<TId>
151151
{
152-
return _genericProcessorFactory.GetProcessor<IEntityReadRepository<TEntity, TId>>(typeof(IEntityReadRepository<,>), typeof(TEntity), typeof(TId));
152+
return _genericProcessorFactory.GetProcessor<IResourceReadRepository<TEntity, TId>>(typeof(IResourceReadRepository<,>), typeof(TEntity), typeof(TId));
153153
}
154154

155155

0 commit comments

Comments
 (0)