// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { // Authentication services.AddAuthenticationService(Configuration.BindSettings <ApiSecuritySettings>(Core.Constants.Settings.ApiSecuritySettingsSectionName)); services.AddMvc(option => option.EnableEndpointRouting = false); services.AddMvc(config => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); config.Filters.Add(new AuthorizeFilter(policy)); }); //Fluent Validation services.AddMvc() .AddFluentValidation(o => { o.RegisterValidatorsFromAssemblyContaining <UserDTOValidator>(); }); // DI DependencyBuilder.AddDependencies(services, Configuration); // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "WhiteLabel API", Description = "WhiteLabel ASP.NET Core Web API", TermsOfService = new Uri("https://www.yourwebsite.com/termsandservice") }); c.AddFluentValidationRules(); c.AddSecurityDefinition("basic", new OpenApiSecurityScheme { Name = "Authorization", Type = SecuritySchemeType.Http, Scheme = "basic", In = ParameterLocation.Header, Description = "Basic Authorization header using the Bearer scheme." }); c.DocumentFilter <SecurityRequirementsDocumentFilter>(); }); services.ConfigureSwaggerGen(options => { options.CustomSchemaIds(x => x.FullName); }); #region New AutoMapper Configuration var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new ObjectProfile()); mc.AddProfile(new ModelProfile()); }); IMapper mapper = mappingConfig.CreateMapper(); services.AddSingleton(mapper); #endregion services.AddCors(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Authentication services.AddAuthenticationService(Configuration.BindSettings <ApiSecuritySettings>(Constants.ApiSecuritySettingsSectionName)); // Add framework services. services.AddMvc(config => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); config.Filters.Add(new AuthorizeFilter(policy)); }) .AddJsonOptions(options => { options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc; options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); // DI DependencyBuilder.AddDependencies(services, Configuration); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Applications API", Version = "v2" }); c.DescribeAllEnumsAsStrings(); c.AddSecurityDefinition("basic", new BasicAuthScheme { Type = "basic", Description = "Basic HTTP Authentication" }); c.DocumentFilter <SecurityRequirementsDocumentFilter>(); }); services.ConfigureSwaggerGen(options => { options.CustomSchemaIds(x => x.FullName); }); #region New AutoMapper configuration 2.2 //var mappingConfig = new MapperConfiguration(mc => //{ // mc.AddProfile(new ObjectProfile()); // mc.AddProfile(new ModelProfile()); //}); //IMapper mapper = mappingConfig.CreateMapper(); //services.AddSingleton(mapper); #endregion #region New Logging builder 2.2 //services.AddLogging(loggingBuilder => //{ // loggingBuilder.AddConfiguration(Configuration.GetSection("Logging")); // loggingBuilder.AddConsole(); // loggingBuilder.AddDebug(); //}); #endregion //services.AddCors(); }