Skip to content

Commit be460b3

Browse files
committed
feat(entity-repository): add default generic int type
1 parent 3ffb6b3 commit be460b3

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

src/JsonApiDotNetCore/Data/DefaultEntityRepository.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88

99
namespace JsonApiDotNetCore.Data
1010
{
11+
public class DefaultEntityRepository<TEntity>
12+
: DefaultEntityRepository<TEntity, int>,
13+
IEntityRepository<TEntity>
14+
where TEntity : class, IIdentifiable<int>
15+
{
16+
public DefaultEntityRepository(
17+
DbContext context,
18+
ILoggerFactory loggerFactory,
19+
IJsonApiContext jsonApiContext)
20+
: base(context, loggerFactory, jsonApiContext)
21+
{ }
22+
}
23+
1124
public class DefaultEntityRepository<TEntity, TId>
1225
: IEntityRepository<TEntity, TId>
1326
where TEntity : class, IIdentifiable<TId>

src/JsonApiDotNetCore/Data/IEntityRepository.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
namespace JsonApiDotNetCore.Data
66
{
7+
public interface IEntityRepository<TEntity>
8+
: IEntityRepository<TEntity, int>
9+
where TEntity : class, IIdentifiable<int>
10+
{
11+
}
12+
713
public interface IEntityRepository<TEntity, in TId>
814
where TEntity : class, IIdentifiable<TId>
915
{

src/JsonApiDotNetCore/Extensions/ServiceProviderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public static void AddJsonApiInternals<TContext>(this IServiceCollection service
2626

2727
services.AddScoped(typeof(DbContext), typeof(TContext));
2828

29+
services.AddScoped(typeof(IEntityRepository<>), typeof(DefaultEntityRepository<>));
2930
services.AddScoped(typeof(IEntityRepository<,>), typeof(DefaultEntityRepository<,>));
30-
// services.AddScoped(typeof(IEntityRepository<,>), typeof(DefaultEntityRepository<,>));
3131

3232
services.AddSingleton<IContextGraph>(contextGraph);
3333
services.AddSingleton<IJsonApiContext, JsonApiContext>();

src/JsonApiDotNetCoreExample/Controllers/PeopleController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class PeopleController : JsonApiController<Person>
1212
{
1313
public PeopleController(
1414
IJsonApiContext jsonApiContext,
15-
IEntityRepository<Person, int> entityRepository,
15+
IEntityRepository<Person> entityRepository,
1616
ILoggerFactory loggerFactory)
1717
: base(jsonApiContext, entityRepository, loggerFactory)
1818
{ }

src/JsonApiDotNetCoreExample/Controllers/TodoItemsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class TodoItemsController : JsonApiController<TodoItem>
1212
{
1313
public TodoItemsController(
1414
IJsonApiContext jsonApiContext,
15-
IEntityRepository<TodoItem, int> entityRepository,
15+
IEntityRepository<TodoItem> entityRepository,
1616
ILoggerFactory loggerFactory)
1717
: base(jsonApiContext, entityRepository, loggerFactory)
1818
{ }

0 commit comments

Comments
 (0)