// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } /// var swaggerOptions = new SwaggerOptionsConfig(); Configuration.GetSection(nameof(SwaggerOptionsConfig)).Bind(swaggerOptions); app.UseSwagger(options => { options.RouteTemplate = swaggerOptions.JsonRoute; }); app.UseSwaggerUI(options => { options.SwaggerEndpoint(swaggerOptions.UiEndpoint, swaggerOptions.Description); }); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/swagger/{action=Index}/{id?}"); }); }
public static SwaggerOptionsConfig GetSwaggerConfig(this IConfiguration configuration, string sectionName) { SwaggerOptionsConfig config = new SwaggerOptionsConfig(); configuration.Bind(sectionName, config); return(config); }
// 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) { SwaggerOptionsConfig swaggerOptionsConfig = Configuration.GetSection(SwaggerOptionsConfig.Position).Get <SwaggerOptionsConfig>(); CorsConfig corsConfig = Configuration.GetSection(CorsConfig.Position).Get <CorsConfig>(); // Add functionality to inject IOptions<T> services.AddOptions(); // Add our Config object so it can be injected services.Configure <SwaggerOptionsConfig>(Configuration.GetSection(SwaggerOptionsConfig.Position)) .Configure <UploadedConfig>(Configuration.GetSection(UploadedConfig.Position)) .Configure <CorsConfig>(Configuration.GetSection(CorsConfig.Position)); // CORS Settings services.AddCorsPolicy(corsConfig); //load here other external dll controllers classes (before the AddMvc/Routing) //https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-2.2#use-routing-middleware services.AddMvc().AddJsonOptions(options => { options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); options.JsonSerializerOptions.Converters.Add(new PointConverter()); options.JsonSerializerOptions.IgnoreNullValues = true; options.JsonSerializerOptions.WriteIndented = true; }); services.AddIdentityServerService <UserValidation>(Environment, Configuration); // Swagger UI services.AddSwaggerGen(c => c.SwaggerDoc(swaggerOptionsConfig.Version, new OpenApiInfo { Title = swaggerOptionsConfig.Title, Version = swaggerOptionsConfig.Version })); // Configure object mapping (AutoMapper), Get the assembly, AutoMapper will scan our assembly and look for classes that inherit from Profile services.AddAutoMapper(typeof(MappingProfile)); }