コード例 #1
0
        /// <summary>
        /// Configures the services.
        /// </summary>
        /// <param name="services">The services.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            ConfigurationOptions.ConfigureService(services, Configuration);

            // Add framework services.
            services.AddMvc(
                options =>
            {
                options.Filters.Add(typeof(ValidateModelStateAttribute));
            });
            // Remove commented code and above semicolon
            // if the assembly of the API Controllers is different than project which contains Startup class
            //.AddApplicationPart(typeof(BaseController<>).Assembly);

            // Localization support
            LocalizationConfiguration.ConfigureService(services);

            Mapper.Reset();
            // https://github.com/AutoMapper/AutoMapper.Extensions.Microsoft.DependencyInjection/issues/28
            services.AddAutoMapper(typeof(Startup));

            // Swagger API documentation
            SwaggerConfiguration.ConfigureService(services);

            // IOC containers / Entity Framework
            EntityFrameworkConfiguration.ConfigureService(services, Configuration);
            IocContainerConfiguration.ConfigureService(services, Configuration);
            ApiVersioningConfiguration.ConfigureService(services);
        }
コード例 #2
0
        /// <summary>
        /// Configures the services.
        /// </summary>
        /// <param name="services">The services.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            ConfigurationOptions.ConfigureService(services, Configuration);

            // Add framework services.
            services.AddMvc(
                options =>
            {
                options.Filters.Add(typeof(ValidateModelStateAttribute));
            });
            // Remove the commented code below and add before semicolon in the above line
            // if the assembly of the API Controllers is different than project which contains Startup class
            //.AddApplicationPart(typeof(BaseController<>).Assembly);

            if (_env.IsProduction())
            {
                services.AddHsts(options =>
                {
                    options.Preload           = true;
                    options.IncludeSubDomains = true;
                    options.MaxAge            = TimeSpan.FromDays(60);
                });
            }
            // Localization support
            LocalizationConfiguration.ConfigureService(services);
# if UseAuthentication