Last active
April 16, 2020 11:12
-
-
Save enisn/0c971d45d10c6c62fa10b70999014176 to your computer and use it in GitHub Desktop.
Multi-Targeting Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Startup | |
{ | |
public Startup(IConfiguration configuration) | |
{ | |
Configuration = configuration; | |
} | |
public IConfiguration Configuration { get; } | |
// This method gets called by the runtime. Use this method to add services to the container. | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services | |
#if NETCOREAPP2_2 | |
.AddMvc() | |
#endif | |
#if NETCOREAPP3_0 || NETCOREAPP3_1 | |
.AddControllersWithViews() | |
.AddNewtonsoftJson(opts => | |
{ | |
opts.SerializerSettings.MaxDepth = 1; | |
opts.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; | |
opts.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; | |
}) | |
#endif | |
; | |
services.AddMemoryCache(); | |
services.AddAuthentication(); | |
services.AddSwaggerGen(opts => | |
{ | |
opts.SwaggerDoc("v1", new OpenApiInfo { Title = "Recipes Document", Version = "v1" }); | |
}); | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
#if NETCOREAPP3_0 || NETCOREAPP3_1 | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
#endif | |
#if NETCOREAPP2_2 | |
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | |
#endif | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
app.UseSwagger(); | |
app.UseSwaggerUI(c => | |
{ | |
c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1"); | |
}); | |
#if NETCOREAPP2_2 | |
app.UseAuthentication(); | |
app.UseMvc(); | |
#endif | |
#if NETCOREAPP3_0 || NETCOREAPP3_1 | |
app.UseHttpsRedirection(); | |
app.UseRouting(); | |
app.UseAuthorization(); | |
app.UseEndpoints(endpoints => | |
{ | |
endpoints.MapControllers(); | |
}); | |
#endif | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment