// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers() .AddNewtonsoftJson(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver() { NamingStrategy = new SnakeCaseNamingStrategy() }; } ) ; services.AddAuthentication(options => { options.DefaultAuthenticateScheme = ApiKeyAuthenticationOptions.DefaultScheme; options.DefaultChallengeScheme = ApiKeyAuthenticationOptions.DefaultScheme; }).AddApiKeySupport(options => { }); services.AddAuthorization(options => { options.AddPolicy(Policies.OnlyEmployees, policy => policy.Requirements.Add(new OnlyReadRequirement())); options.AddPolicy(Policies.OnlyManagers, policy => policy.Requirements.Add(new OnlyWriteRequirement())); options.AddPolicy(Policies.OnlyThirdParties, policy => policy.Requirements.Add(new OnlyMonitorRequirement())); }); services.AddSingleton <IAuthorizationHandler, OnlyReadAuthorizationHandler>(); services.AddSingleton <IAuthorizationHandler, OnlyWriteAuthorizationHandler>(); services.AddSingleton <IAuthorizationHandler, OnlyMonitorPartiesAuthorizationHandler>(); services.AddSingleton <IGetApiKeyQuery, InMemoryGetApiKeyQuery>(); // Register the Swagger generator, defining one or more Swagger documents SwaggerInitializer.AddSwagger(services); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var mvcBuilder = services.AddMvc(); services.AddAutoMapper(); new ServiceInitializer().RegisterServices(mvcBuilder, services, (IConfigurationRoot)Configuration); SwaggerInitializer.RegisterSwagger(services); }
private IMicroserviceInitializer CreateSwaggerInitializer(IConfiguration configuration, Action <SwaggerInitializerOptions> configure) { var initializer = new SwaggerInitializer(configuration); configure?.Invoke(initializer.Options); return(initializer); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { SwaggerInitializer.Configure(services); SetupCommanderDatabase(services); services.AddControllers().AddNewtonsoftJson(serializer => serializer.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver()); AutoMapperInitializer.Configure(services); RepositoryInitializer.Configure(services); BusinessServiceInitializer.Configure(services); DALInitializer.Configure(services); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } SwaggerInitializer.Configure(app); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }