/// <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); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Add catalog db context EFConfiguration.ConfigureService(services, Configuration); // IOC containers / Entity Framework StationeryConfiguration.ConfigureService(services); CatalogConfiguration.ConfigureService(services); // config connections options ConfigurationOptions.ConfigureService(services, this.Configuration); ManagerConfiguration.ConfigureService(services); // config jwtfactory and authenticatioin this.ConfigAuthentication(services); // Add framework services. services.AddLogging(); services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); }); services.AddMvc().AddJsonOptions(options => { options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; }).SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }
/// <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
public void ConfigureServices(IServiceCollection services) { ConfigurationOptions.ConfigureService(services, Configuration); services.AddMvc( options => { options.Filters.Add(typeof(ValidateModelStateAttribute)); }); Mapper.Reset(); services.AddAutoMapper(typeof(Startup)); // Swagger API documentation SwaggerConfiguration.ConfigureService(services); EntityFrameworkConfiguration.ConfigureService(services, Configuration); IocContainerConfiguration.ConfigureService(services, Configuration); ApiVersioningConfiguration.ConfigureService(services); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = "JwtBearer"; options.DefaultChallengeScheme = "JwtBearer"; }) .AddJwtBearer("JwtBearer", jwtBearerOptions => { jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Constants.SymmetricSecurityKey)), ValidateIssuer = false, ValidateAudience = false, ValidateLifetime = true, //validate the expiration and not before values in the token ClockSkew = TimeSpan.FromMinutes(5) //5 minute tolerance for the expiration date }; jwtBearerOptions.Events = new JwtBearerEvents { OnTokenValidated = context => { var slug = context.HttpContext.Request.Headers[Constants.TenantId].ToString(); if (context.SecurityToken is JwtSecurityToken accessToken && !string.IsNullOrWhiteSpace(slug)) { if (accessToken.Claims.Where(claim => claim.Type.Equals(ClaimTypes.PrimaryGroupSid)).Any(claim => slug == claim.Value)) { return(Task.CompletedTask); } } context.Fail($"Invalid 'slug'"); return(Task.CompletedTask); } }; });
/// <summary> /// Configures the services. /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services">The services.</param> public void ConfigureServices(IServiceCollection services) { ConfigurationOptions.ConfigureService(services, Configuration); // Add framework services. services.AddMvc(); IocContainerConfiguration.ConfigureService(services, Configuration); SwaggerConfiguration.ConfigureService(services); }
/// <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(); // Swagger API documentation SwaggerConfiguration.ConfigureService(services); // IOC containers / Entity Framework EntityFrameworkConfiguration.ConfigureService(services, Configuration); IocContainerConfiguration.ConfigureService(services, Configuration); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddAutoMapper(typeof(MappingProfile)); ConfigurationOptions.ConfigureService(services, Configuration); // IOC containers IocContainerConfiguration.ConfigureService(services, Configuration); // JWT containers JwtConfiguration.ConfigureService(services, Configuration); // Swagger API documentation SwaggerConfiguration.ConfigureService(services); // Cors Orgin CorsOrginConfiguration.ConfigureService(services); }