|
|
|
@ -14,9 +14,6 @@ namespace Volo.Abp.AutoMapper
|
|
|
|
|
[DependsOn(typeof(AbpObjectMappingModule))]
|
|
|
|
|
public class AbpAutoMapperModule : AbpModule
|
|
|
|
|
{
|
|
|
|
|
private static volatile bool _createdMappingsBefore;
|
|
|
|
|
private static readonly object SyncObj = new object();
|
|
|
|
|
|
|
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
|
|
|
{
|
|
|
|
|
var mapperAccessor = new MapperAccessor();
|
|
|
|
@ -30,8 +27,6 @@ namespace Volo.Abp.AutoMapper
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateMappings(IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
lock (SyncObj)
|
|
|
|
|
{
|
|
|
|
|
using (var scope = serviceProvider.CreateScope())
|
|
|
|
|
{
|
|
|
|
@ -54,35 +49,14 @@ namespace Volo.Abp.AutoMapper
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.UseStaticMapper)
|
|
|
|
|
{
|
|
|
|
|
//We should prevent duplicate mapping in an application, since Mapper is static.
|
|
|
|
|
if (!_createdMappingsBefore)
|
|
|
|
|
{
|
|
|
|
|
_createdMappingsBefore = true;
|
|
|
|
|
|
|
|
|
|
Mapper.Initialize(mapperConfigurationExpression =>
|
|
|
|
|
{
|
|
|
|
|
ConfigureAll(new AbpAutoMapperConfigurationContext(mapperConfigurationExpression, scope.ServiceProvider));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ValidateAll(Mapper.Configuration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scope.ServiceProvider.GetRequiredService<MapperAccessor>().Mapper = Mapper.Instance;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var config = new MapperConfiguration(mapperConfigurationExpression =>
|
|
|
|
|
var mapperConfiguration = new MapperConfiguration(mapperConfigurationExpression =>
|
|
|
|
|
{
|
|
|
|
|
ConfigureAll(new AbpAutoMapperConfigurationContext(mapperConfigurationExpression, scope.ServiceProvider));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ValidateAll(config);
|
|
|
|
|
ValidateAll(mapperConfiguration);
|
|
|
|
|
|
|
|
|
|
scope.ServiceProvider.GetRequiredService<MapperAccessor>().Mapper = config.CreateMapper();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
scope.ServiceProvider.GetRequiredService<MapperAccessor>().Mapper = mapperConfiguration.CreateMapper();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|