|
|
|
@ -13,7 +13,7 @@ namespace Volo.Abp.AutoMapper |
|
|
|
typeof(AbpObjectMappingModule), |
|
|
|
typeof(AbpObjectExtendingModule), |
|
|
|
typeof(AbpAuditingModule) |
|
|
|
)] |
|
|
|
)] |
|
|
|
public class AbpAutoMapperModule : AbpModule |
|
|
|
{ |
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context) |
|
|
|
@ -21,16 +21,11 @@ namespace Volo.Abp.AutoMapper |
|
|
|
context.Services.AddAutoMapperObjectMapper(); |
|
|
|
|
|
|
|
var mapperAccessor = new MapperAccessor(); |
|
|
|
context.Services.AddSingleton<IMapperAccessor>(_ => mapperAccessor); |
|
|
|
context.Services.AddSingleton<MapperAccessor>(_ => mapperAccessor); |
|
|
|
context.Services.AddSingleton(_ => mapperAccessor); |
|
|
|
context.Services.Add(new ServiceDescriptor(typeof(IMapperAccessor), CreateMappings, ServiceLifetime.Singleton)); |
|
|
|
} |
|
|
|
|
|
|
|
public override void OnPreApplicationInitialization(ApplicationInitializationContext context) |
|
|
|
{ |
|
|
|
CreateMappings(context.ServiceProvider); |
|
|
|
} |
|
|
|
|
|
|
|
private void CreateMappings(IServiceProvider serviceProvider) |
|
|
|
private IMapperAccessor CreateMappings(IServiceProvider serviceProvider) |
|
|
|
{ |
|
|
|
using (var scope = serviceProvider.CreateScope()) |
|
|
|
{ |
|
|
|
@ -48,7 +43,7 @@ namespace Volo.Abp.AutoMapper |
|
|
|
{ |
|
|
|
foreach (var profileType in options.ValidatingProfiles) |
|
|
|
{ |
|
|
|
config.AssertConfigurationIsValid(((Profile)Activator.CreateInstance(profileType)).ProfileName); |
|
|
|
config.AssertConfigurationIsValid(((Profile) Activator.CreateInstance(profileType)).ProfileName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -59,7 +54,10 @@ namespace Volo.Abp.AutoMapper |
|
|
|
|
|
|
|
ValidateAll(mapperConfiguration); |
|
|
|
|
|
|
|
scope.ServiceProvider.GetRequiredService<MapperAccessor>().Mapper = mapperConfiguration.CreateMapper(); |
|
|
|
var mapperAccessor = scope.ServiceProvider.GetRequiredService<MapperAccessor>(); |
|
|
|
mapperAccessor.Mapper = new Mapper(mapperConfiguration, serviceProvider.GetService); |
|
|
|
|
|
|
|
return mapperAccessor; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|