Skip to content

Commit 49127e5

Browse files
committed
remove automapper and create resource mapper generic interface. kept it untyped for now to match how automapper works
1 parent 6e9776b commit 49127e5

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/JsonApiDotNetCore/JsonApiDotNetCore.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
</PropertyGroup>
2222

2323
<ItemGroup>
24-
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="4.0.1" />
2524
<PackageReference Include="Ben.Demystifier" Version="0.1.1" />
2625
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="$(AspNetCoreVersion)" />
2726
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="$(AspNetCoreVersion)" />
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace JsonApiDotNetCore.Models
2+
{
3+
public interface IResourceMapper
4+
{
5+
/// <summary>
6+
/// Execute a mapping from the source object to a new destination object.
7+
/// The source type is inferred from the source object.
8+
/// </summary>
9+
/// <typeparam name="TDestination">Destination type to create</typeparam>
10+
/// <param name="source">Source object to map from</param>
11+
/// <returns>Mapped destination object</returns>
12+
TDestination Map<TDestination>(object source);
13+
14+
/// <summary>
15+
/// Execute a mapping from the source object to a new destination object.
16+
/// </summary>
17+
/// <typeparam name="TSource">Source type to use, regardless of the runtime type</typeparam>
18+
/// <typeparam name="TDestination">Destination type to create</typeparam>
19+
/// <param name="source">Source object to map from</param>
20+
/// <returns>Mapped destination object</returns>
21+
TDestination Map<TSource, TDestination>(TSource source);
22+
}
23+
}

src/JsonApiDotNetCore/Services/DefaultResourceService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using AutoMapper;
21
using JsonApiDotNetCore.Data;
32
using JsonApiDotNetCore.Internal;
43
using JsonApiDotNetCore.Models;
@@ -42,7 +41,7 @@ public class DefaultResourceService<TResource, TEntity, TId> :
4241
private readonly IJsonApiContext _jsonApiContext;
4342
private readonly IEntityRepository<TEntity, TId> _entities;
4443
private readonly ILogger _logger;
45-
private readonly IMapper _mapper;
44+
private readonly IResourceMapper _mapper;
4645

4746
public DefaultResourceService(
4847
IJsonApiContext jsonApiContext,
@@ -65,7 +64,7 @@ public DefaultResourceService(
6564
IJsonApiContext jsonApiContext,
6665
IEntityRepository<TEntity, TId> entityRepository,
6766
ILoggerFactory loggerFactory,
68-
IMapper mapper)
67+
IResourceMapper mapper)
6968
{
7069
_jsonApiContext = jsonApiContext;
7170
_entities = entityRepository;

0 commit comments

Comments
 (0)