Пример #1
0
 /// <summary>
 /// Add to a list of AutoMapper configuration expressions that will be invoked by the implementor.
 /// </summary>
 /// <param name="expressions">The expressions to invoke after service registrations.</param>
 public void AddMapperExtensionExpressions(IList <Expression <Action <IMapperConfigurationExpression> > > expressions)
 {
     foreach (Expression <Action <IMapperConfigurationExpression> > expression in expressions)
     {
         MapperExtensionExpressions.Add(expression);
     }
 }
Пример #2
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        public Startup()
        {
            ServiceRegistrationExpressions.Add(() => ServiceCollection.RegisterConfiguredOptions <SwaggerOptions>(Configuration));
            ServiceRegistrationExpressions.Add(() => ServiceCollection.RegisterConfiguredOptions <HealthChecksUIOptions>(Configuration));
            ServiceRegistrationExpressions.Add(() => ServiceCollection.AddTransient(typeof(IHttpContextAccessor), typeof(HttpContextAccessor)));
            ServiceRegistrationExpressions.Add(() => ServiceCollection.AddTransient(typeof(IActionContextAccessor), typeof(ActionContextAccessor)));
            ServiceRegistrationExpressions.Add(() => ServiceCollection.AddCors());
            ServiceRegistrationExpressions.Add(() => ServiceCollection.AddAuthentication());
            ServiceRegistrationExpressions.Add(() => ServiceCollection.AddAuthorization());
            ServiceRegistrationExpressions.Add(() => ServiceCollection.AddHealthChecks());
            ServiceRegistrationExpressions.Add(() => AddMvcCore());
            ServiceRegistrationExpressions.Add(() => AddSwagger());
            ServiceRegistrationExpressions.Add(() => AddHealthChecks());

            MapperExtensionExpressions.Add(mapperConfig => mapperConfig.AddProfile(typeof(PresentationProfile)));
        }
Пример #3
0
        private void RegisterAutoMapper()
        {
            ServiceCollection.AddSingleton(serviceProvider =>
            {
                var configurationExpression = new MapperConfigurationExpression();
                AugmentExpressionExecution(() => configurationExpression.ConstructServicesUsing(serviceProvider.GetService));
                AugmentExpressionExecutions(MapperExtensionExpressions, configurationExpression);
                var configuration = new MapperConfiguration(configurationExpression);
                return(configuration.CreateMapper());
            });

            // Profiles
            MapperExtensionExpressions.Add(mapperConfig => mapperConfig.AddProfile(typeof(ApplicationProfile)));

            // AutoMapper Resolvers
            ServiceCollection.AddSingleton(typeof(INowValueResolver <,>), typeof(NowValueResolver <,>));
            ServiceCollection.AddSingleton(typeof(IStringKeyValueResolver <,>), typeof(StringKeyValueResolver <,>));
        }