mirror of https://github.com/abpframework/abp.git
5 changed files with 45 additions and 16 deletions
@ -1,27 +1,25 @@ |
|||
using System; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.ObjectMapping; |
|||
|
|||
namespace Volo.Abp.AutoMapper |
|||
{ |
|||
[Dependency(ServiceLifetime.Transient, ReplaceServices = true)] |
|||
public class AutoMapperObjectMapper : DefaultObjectMapper |
|||
public class AutoMapperAutoObjectMappingProvider : IAutoObjectMappingProvider |
|||
{ |
|||
protected IMapperAccessor MapperAccessor { get; } |
|||
|
|||
public AutoMapperObjectMapper(IMapperAccessor mapperAccessor, IServiceProvider serviceProvider) |
|||
: base(serviceProvider) |
|||
public AutoMapperAutoObjectMappingProvider(IMapperAccessor mapperAccessor) |
|||
{ |
|||
MapperAccessor = mapperAccessor; |
|||
} |
|||
|
|||
protected override TDestination AutoMap<TSource, TDestination>(object source) |
|||
public virtual TDestination Map<TSource, TDestination>(object source) |
|||
{ |
|||
return MapperAccessor.Mapper.Map<TDestination>(source); |
|||
} |
|||
|
|||
protected override TDestination AutoMap<TSource, TDestination>(TSource source, TDestination destination) |
|||
public virtual TDestination Map<TSource, TDestination>(TSource source, TDestination destination) |
|||
{ |
|||
return MapperAccessor.Mapper.Map(source, destination); |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
namespace Volo.Abp.ObjectMapping |
|||
{ |
|||
public interface IAutoObjectMappingProvider |
|||
{ |
|||
TDestination Map<TSource, TDestination>(object source); |
|||
|
|||
TDestination Map<TSource, TDestination>(TSource source, TDestination destination); |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.ObjectMapping |
|||
{ |
|||
public sealed class NotImplementedAutoObjectMappingProvider : IAutoObjectMappingProvider, ISingletonDependency |
|||
{ |
|||
public TDestination Map<TSource, TDestination>(object source) |
|||
{ |
|||
throw new NotImplementedException($"Can not map from given object ({source}) to {typeof(TDestination).AssemblyQualifiedName}."); |
|||
} |
|||
|
|||
public TDestination Map<TSource, TDestination>(TSource source, TDestination destination) |
|||
{ |
|||
throw new NotImplementedException($"Can no map from {typeof(TSource).AssemblyQualifiedName} to {typeof(TDestination).AssemblyQualifiedName}."); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue