| | 1 | | using Api; |
| | 2 | | using Api.Middleware; |
| | 3 | | using Api.ServiceExtension; |
| | 4 | | using Application; |
| | 5 | | using Domain; |
| | 6 | | using HealthChecks.UI.Client; |
| | 7 | | using Infrastructure; |
| | 8 | | using Microsoft.AspNetCore.Diagnostics.HealthChecks; |
| | 9 | | using Microsoft.AspNetCore.Hosting; |
| | 10 | | using Microsoft.AspNetCore.ResponseCompression; |
| | 11 | | using Serilog; |
| | 12 | |
|
| 1 | 13 | | var builder = WebApplication.CreateBuilder(args); |
| | 14 | |
|
| | 15 | | #region logging |
| 1 | 16 | | Log.Logger = new LoggerConfiguration() |
| 1 | 17 | | .ReadFrom.Configuration(builder.Configuration) |
| 1 | 18 | | .Enrich.FromLogContext() |
| 1 | 19 | | .CreateLogger(); |
| | 20 | |
|
| 1 | 21 | | builder.Host.UseSerilog(); |
| | 22 | | #endregion logging |
| | 23 | |
|
| 1 | 24 | | builder.Services.AddDefaultProblemDetails(); |
| 1 | 25 | | builder.Services.AddDefaultApiVersioning(); |
| 1 | 26 | | builder.Services.AddDefaultResponseCompression(); |
| 1 | 27 | | builder.Services.AddDefaultSwaggerGeneration(); |
| | 28 | |
|
| 1 | 29 | | builder.Services.AddDomain(); |
| 1 | 30 | | builder.Services.AddInfrastructure(); |
| 1 | 31 | | builder.Services.AddApplication(); |
| | 32 | |
|
| 1 | 33 | | builder.Services.AddControllers(); |
| 1 | 34 | | builder.Services.AddEndpointsApiExplorer(); |
| 1 | 35 | | builder.Services.AddSwaggerGen(); |
| | 36 | |
|
| 1 | 37 | | builder.Services.AddMemoryCache(); |
| | 38 | |
|
| 1 | 39 | | builder.Services.AddHttpContextAccessor(); |
| | 40 | |
|
| 1 | 41 | | builder.Services.AddSingleton<Banner>(); |
| 1 | 42 | | var app = builder.Build(); |
| 1 | 43 | | app.UseHttpsRedirection(); |
| | 44 | |
|
| 1 | 45 | | app.UseAuthorization(); |
| | 46 | |
|
| 1 | 47 | | app.MapControllers(); |
| | 48 | |
|
| 1 | 49 | | app.UseResponseCompression(); |
| | 50 | |
|
| 2 | 51 | | if (app.Environment.IsDevelopment() || app.Environment.IsProduction()) { |
| 1 | 52 | | app.UseSwagger(); |
| 2 | 53 | | app.UseSwaggerUI(options => { |
| 1 | 54 | | options.SwaggerEndpoint("../swagger/v1/swagger.json", "Cleanarchitecture Template API V1"); |
| 1 | 55 | | options.DefaultModelRendering(Swashbuckle.AspNetCore.SwaggerUI.ModelRendering.Model); |
| 1 | 56 | | options.ConfigObject.AdditionalItems["syntaxHighlight"] = false; |
| 2 | 57 | | }); |
| 1 | 58 | | } |
| | 59 | |
|
| 2 | 60 | | if (app.Environment.IsDevelopment() || app.Environment.IsStaging()) { |
| 1 | 61 | | app.UseDeveloperExceptionPage(); |
| 1 | 62 | | } |
| 0 | 63 | | else { |
| 0 | 64 | | app.UseExceptionHandler(); |
| 0 | 65 | | } |
| | 66 | |
|
| | 67 | |
|
| | 68 | | //app.MapHealthChecks( |
| | 69 | | // "_health", |
| | 70 | | // new HealthCheckOptions() { |
| | 71 | | // ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse |
| | 72 | | // }); |
| | 73 | |
|
| 2 | 74 | | using (var banner = app.Services.GetRequiredService<Banner>()) { |
| 1 | 75 | | banner.LogBanner(); |
| 1 | 76 | | } |
| | 77 | |
|
| 1 | 78 | | await app.RunAsync(); |