| | 1 | | using Api; |
| | 2 | | using Api.Middleware; |
| | 3 | | using Api.Request.Parameters; |
| | 4 | | using Api.Request.Validation; |
| | 5 | | using Api.ServiceExtension; |
| | 6 | | using Application; |
| | 7 | | using Domain; |
| | 8 | | using FluentValidation; |
| | 9 | | using FluentValidation.AspNetCore; |
| | 10 | | using Infrastructure; |
| | 11 | | using Serilog; |
| | 12 | |
|
| 1 | 13 | | var builder = WebApplication.CreateBuilder(args); |
| | 14 | |
|
| 1 | 15 | | builder.Host.UseSerilog(); |
| 1 | 16 | | builder.Services.AddDefaultLogger(builder.Configuration); |
| | 17 | |
|
| 1 | 18 | | builder.Services.AddOpenTelemetryWithExporters( |
| 1 | 19 | | builder.Configuration, |
| 1 | 20 | | TelemetryExporters.Jaeger | TelemetryExporters.Zipkin); |
| | 21 | |
|
| 1 | 22 | | builder.Services.AddDefaultProblemDetails(); |
| 1 | 23 | | builder.Services.AddDefaultApiVersioning(); |
| 1 | 24 | | builder.Services.AddDefaultResponseCompression(); |
| 1 | 25 | | builder.Services.AddDefaultSwaggerGeneration(); |
| | 26 | |
|
| 1 | 27 | | builder.Services.AddSwaggerGen(); |
| | 28 | |
|
| 1 | 29 | | builder.Services.AddDomain(); |
| 1 | 30 | | builder.Services.AddInfrastructure( |
| 1 | 31 | | builder.Environment, |
| 1 | 32 | | builder.Configuration |
| 1 | 33 | | ); |
| 1 | 34 | | builder.Services.AddApplication(); |
| | 35 | |
|
| 1 | 36 | | builder.Services.AddProblemDetails(); |
| 1 | 37 | | builder.Services.AddExceptionHandler<GlobalExceptionHandler>(); |
| | 38 | |
|
| 1 | 39 | | builder.Services.AddControllers(); |
| 1 | 40 | | builder.Services.AddEndpointsApiExplorer(); |
| 1 | 41 | | builder.Services.AddSwaggerGen(); |
| | 42 | |
|
| 1 | 43 | | builder.Services.AddMemoryCache(); |
| | 44 | |
|
| 1 | 45 | | builder.Services.AddHttpContextAccessor(); |
| | 46 | |
|
| 1 | 47 | | builder.Services |
| 1 | 48 | | .AddFluentValidationAutoValidation(fv => { |
| 1 | 49 | | fv.DisableDataAnnotationsValidation = true; |
| 1 | 50 | | }) |
| 1 | 51 | | .AddValidatorsFromAssemblyContaining<CustomerRequestValidator>(); |
| | 52 | |
|
| 1 | 53 | | builder.Services |
| 1 | 54 | | .AddControllers(options => { |
| 1 | 55 | | options.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true; |
| 1 | 56 | | }) |
| 1 | 57 | | .AddJsonOptions(opts => { |
| 1 | 58 | | opts.JsonSerializerOptions.WriteIndented = false; |
| 2 | 59 | | }); |
| | 60 | |
|
| | 61 | |
|
| 1 | 62 | | builder.Services.AddSingleton<Banner>(); |
| | 63 | |
|
| 1 | 64 | | var app = builder.Build(); |
| | 65 | |
|
| 1 | 66 | | app.UseExceptionHandler(); |
| 1 | 67 | | app.UseStatusCodePages(); |
| | 68 | |
|
| 1 | 69 | | app.UseHttpsRedirection(); |
| | 70 | |
|
| 1 | 71 | | app.UseAuthorization(); |
| | 72 | |
|
| 1 | 73 | | app.MapControllers(); |
| | 74 | |
|
| 1 | 75 | | app.UseResponseCompression(); |
| | 76 | |
|
| 2 | 77 | | if (app.Environment.IsDevelopment() || app.Environment.IsProduction()) { |
| 1 | 78 | | app.UseSwagger(); |
| 2 | 79 | | app.UseSwaggerUI(options => { |
| 1 | 80 | | options.SwaggerEndpoint("/swagger/v1/swagger.json", "Northwind Api V1"); |
| 1 | 81 | | options.DefaultModelRendering(Swashbuckle.AspNetCore.SwaggerUI.ModelRendering.Model); |
| 1 | 82 | | options.ConfigObject.AdditionalItems["syntaxHighlight"] = false; |
| 1 | 83 | | options.RoutePrefix = "swagger"; |
| 2 | 84 | | }); |
| 1 | 85 | | } |
| | 86 | |
|
| 2 | 87 | | if (app.Environment.IsDevelopment() || app.Environment.IsStaging()) { |
| 1 | 88 | | app.UseDeveloperExceptionPage(); |
| 1 | 89 | | } |
| 0 | 90 | | else { |
| 0 | 91 | | app.UseExceptionHandler(); |
| 0 | 92 | | } |
| | 93 | |
|
| | 94 | |
|
| | 95 | |
|
| | 96 | | //app.MapHealthChecks( |
| | 97 | | // "_health", |
| | 98 | | // new HealthCheckOptions() { |
| | 99 | | // ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse |
| | 100 | | // }); |
| | 101 | |
|
| 2 | 102 | | using (var banner = app.Services.GetRequiredService<Banner>()) { |
| 1 | 103 | | banner.LogBanner(); |
| 1 | 104 | | } |
| | 105 | |
|
| 1 | 106 | | await app.RunAsync(); |