public static void SetupAutoMapper(this IServiceCollection services) { var mapper = MapperService.GetMapper(); services.AddSingleton(mapper); GlobalMapper.Mapper = mapper; }
private static IMapper GetMapper() { var profiles = MapperService.GetAssemblies() .SelectMany(p => p.GetTypes()) .Where(p => p.GetTypeInfo().BaseType == typeof(Profile)); var configuration = new MapperConfiguration(cfg => { cfg.AllowNullCollections = true; cfg.AllowNullDestinationValues = true; foreach (var profile in profiles) { cfg.AddProfile(Activator.CreateInstance(profile) as Profile); } }); return(configuration.CreateMapper()); }
public static void SetupAutoMapper() { var mapper = MapperService.GetMapper(); GlobalMapper.Mapper = mapper; }