Skip to content

Commit 37edd26

Browse files
committed
fix: ambiguous constructor
1 parent 553bf3e commit 37edd26

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/JsonApiDotNetCore/Services/EntityResourceService.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public EntityResourceService(
3232
IEntityRepository<TResource, TId> entityRepository,
3333
ILoggerFactory loggerFactory = null,
3434
IResourceHookExecutor hookExecutor = null) :
35-
base(jsonApiContext, entityRepository, loggerFactory, hookExecutor)
35+
base(jsonApiContext, entityRepository, hookExecutor, loggerFactory)
3636
{ }
3737
}
3838

@@ -47,11 +47,28 @@ public class EntityResourceService<TResource, TEntity, TId> :
4747
private readonly IResourceMapper _mapper;
4848
private readonly IResourceHookExecutor _hookExecutor;
4949

50+
public EntityResourceService(
51+
IJsonApiContext jsonApiContext,
52+
IEntityRepository<TEntity, TId> entityRepository,
53+
IResourceHookExecutor hookExecutor,
54+
ILoggerFactory loggerFactory = null)
55+
{
56+
// no mapper provided, TResource & TEntity must be the same type
57+
if (typeof(TResource) != typeof(TEntity))
58+
{
59+
throw new InvalidOperationException("Resource and Entity types are NOT the same. Please provide a mapper.");
60+
}
61+
62+
_jsonApiContext = jsonApiContext;
63+
_entities = entityRepository;
64+
_hookExecutor = hookExecutor;
65+
_logger = loggerFactory?.CreateLogger<EntityResourceService<TResource, TEntity, TId>>();
66+
}
67+
5068
public EntityResourceService(
5169
IJsonApiContext jsonApiContext,
5270
IEntityRepository<TEntity, TId> entityRepository,
53-
ILoggerFactory loggerFactory = null,
54-
IResourceHookExecutor hookExecutor = null)
71+
ILoggerFactory loggerFactory = null)
5572
{
5673
// no mapper provided, TResource & TEntity must be the same type
5774
if (typeof(TResource) != typeof(TEntity))
@@ -61,7 +78,6 @@ public EntityResourceService(
6178

6279
_jsonApiContext = jsonApiContext;
6380
_entities = entityRepository;
64-
_hookExecutor = hookExecutor;
6581
_logger = loggerFactory?.CreateLogger<EntityResourceService<TResource, TEntity, TId>>();
6682
}
6783

0 commit comments

Comments
 (0)