@@ -47,51 +47,47 @@ public class EntityResourceService<TResource, TEntity, TId> :
47
47
private readonly IResourceMapper _mapper ;
48
48
private readonly IResourceHookExecutor _hookExecutor ;
49
49
50
+
50
51
public EntityResourceService (
51
- IJsonApiContext jsonApiContext ,
52
- IEntityRepository < TEntity , TId > entityRepository ,
53
- IResourceHookExecutor hookExecutor ,
54
- ILoggerFactory loggerFactory = null )
52
+ IJsonApiContext jsonApiContext ,
53
+ IEntityRepository < TEntity , TId > entityRepository ,
54
+ IResourceHookExecutor hookExecutor = null ,
55
+ IResourceMapper mapper = null ,
56
+ ILoggerFactory loggerFactory = null )
55
57
{
56
- // no mapper provided, TResource & TEntity must be the same type
57
- if ( typeof ( TResource ) != typeof ( TEntity ) )
58
+ _jsonApiContext = jsonApiContext ;
59
+ _entities = entityRepository ;
60
+
61
+ if ( mapper == null && typeof ( TResource ) != typeof ( TEntity ) )
58
62
{
59
63
throw new InvalidOperationException ( "Resource and Entity types are NOT the same. Please provide a mapper." ) ;
60
64
}
61
-
62
- _jsonApiContext = jsonApiContext ;
63
- _entities = entityRepository ;
64
65
_hookExecutor = hookExecutor ;
66
+ _mapper = mapper ;
65
67
_logger = loggerFactory ? . CreateLogger < EntityResourceService < TResource , TEntity , TId > > ( ) ;
66
68
}
67
69
70
+
71
+ public EntityResourceService (
72
+ IJsonApiContext jsonApiContext ,
73
+ IEntityRepository < TEntity , TId > entityRepository ,
74
+ IResourceHookExecutor hookExecutor ,
75
+ ILoggerFactory loggerFactory = null ) : this ( jsonApiContext , entityRepository , hookExecutor : hookExecutor , mapper : null , loggerFactory : null )
76
+ { }
77
+
68
78
public EntityResourceService (
69
79
IJsonApiContext jsonApiContext ,
70
80
IEntityRepository < TEntity , TId > entityRepository ,
71
- ILoggerFactory loggerFactory = null )
72
- {
73
- // no mapper provided, TResource & TEntity must be the same type
74
- if ( typeof ( TResource ) != typeof ( TEntity ) )
75
- {
76
- throw new InvalidOperationException ( "Resource and Entity types are NOT the same. Please provide a mapper." ) ;
77
- }
78
-
79
- _jsonApiContext = jsonApiContext ;
80
- _entities = entityRepository ;
81
- _logger = loggerFactory ? . CreateLogger < EntityResourceService < TResource , TEntity , TId > > ( ) ;
82
- }
81
+ ILoggerFactory loggerFactory = null ) : this ( jsonApiContext , entityRepository , hookExecutor : null , mapper : null , loggerFactory : loggerFactory )
82
+ { }
83
83
84
+ [ Obsolete ( "Use ctor with signature (jsonApiContext, entityRepository, hookExecutor = null, mapper = null, loggerFactory = null" ) ]
84
85
public EntityResourceService (
85
86
IJsonApiContext jsonApiContext ,
86
87
IEntityRepository < TEntity , TId > entityRepository ,
87
- IResourceMapper mapper ,
88
- ILoggerFactory loggerFactory = null )
89
- {
90
- _jsonApiContext = jsonApiContext ;
91
- _entities = entityRepository ;
92
- _logger = loggerFactory . CreateLogger < EntityResourceService < TResource , TEntity , TId > > ( ) ;
93
- _mapper = mapper ;
94
- }
88
+ ILoggerFactory loggerFactory ,
89
+ IResourceMapper mapper ) : this ( jsonApiContext , entityRepository , hookExecutor : null , mapper : mapper , loggerFactory : loggerFactory )
90
+ { }
95
91
96
92
public virtual async Task < TResource > CreateAsync ( TResource resource )
97
93
{
0 commit comments