예제 #1
0
        public static void SetupAutoMapper(this IServiceCollection services)
        {
            var mapper = MapperService.GetMapper();

            services.AddSingleton(mapper);

            GlobalMapper.Mapper = mapper;
        }
예제 #2
0
        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());
        }
예제 #3
0
        public static void SetupAutoMapper()
        {
            var mapper = MapperService.GetMapper();

            GlobalMapper.Mapper = mapper;
        }