|
1 | | -using System.Reflection; |
| 1 | +using Dotnet.Samples.AspNetCore.WebApi.Configurations; |
2 | 2 | using Dotnet.Samples.AspNetCore.WebApi.Data; |
3 | 3 | using Dotnet.Samples.AspNetCore.WebApi.Mappings; |
4 | 4 | using Dotnet.Samples.AspNetCore.WebApi.Models; |
|
23 | 23 | * Logging |
24 | 24 | * -------------------------------------------------------------------------- */ |
25 | 25 | Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(builder.Configuration).CreateLogger(); |
| 26 | + |
| 27 | +/* Serilog ------------------------------------------------------------------ */ |
26 | 28 | builder.Host.UseSerilog(); |
27 | 29 |
|
28 | 30 | /* ----------------------------------------------------------------------------- |
29 | 31 | * Services |
30 | 32 | * -------------------------------------------------------------------------- */ |
31 | 33 | builder.Services.AddControllers(); |
32 | 34 |
|
| 35 | +/* Entity Framework Core ---------------------------------------------------- */ |
33 | 36 | builder.Services.AddDbContextPool<PlayerDbContext>(options => |
34 | 37 | { |
35 | 38 | var dataSource = Path.Combine(AppContext.BaseDirectory, "Data", "players-sqlite3.db"); |
|
44 | 47 | builder.Services.AddScoped<IPlayerRepository, PlayerRepository>(); |
45 | 48 | builder.Services.AddScoped<IPlayerService, PlayerService>(); |
46 | 49 | builder.Services.AddMemoryCache(); |
| 50 | + |
| 51 | +/* AutoMapper --------------------------------------------------------------- */ |
47 | 52 | builder.Services.AddAutoMapper(typeof(PlayerMappingProfile)); |
| 53 | + |
| 54 | +/* FluentValidation --------------------------------------------------------- */ |
48 | 55 | builder.Services.AddScoped<IValidator<PlayerRequestModel>, PlayerRequestModelValidator>(); |
49 | 56 |
|
50 | 57 | if (builder.Environment.IsDevelopment()) |
51 | 58 | { |
| 59 | + /* Swagger UI ----------------------------------------------------------- */ |
| 60 | + // https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle |
52 | 61 | builder.Services.AddSwaggerGen(options => |
53 | 62 | { |
54 | 63 | options.SwaggerDoc("v1", builder.Configuration.GetSection("SwaggerDoc").Get<OpenApiInfo>()); |
55 | | - options.IncludeXmlComments( |
56 | | - Path.Combine( |
57 | | - AppContext.BaseDirectory, |
58 | | - $"{Assembly.GetExecutingAssembly().GetName().Name}.xml" |
59 | | - ) |
60 | | - ); |
| 64 | + options.IncludeXmlComments(SwaggerGenDefaults.ConfigureXmlCommentsFilePath()); |
| 65 | + options.AddSecurityDefinition("Bearer", SwaggerGenDefaults.ConfigureSecurityDefinition()); |
| 66 | + options.OperationFilter<AuthorizeCheckOperationFilter>(); |
61 | 67 | }); |
62 | 68 | } |
63 | 69 |
|
|
67 | 73 | * Middlewares |
68 | 74 | * https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware |
69 | 75 | * -------------------------------------------------------------------------- */ |
| 76 | +app.UseSerilogRequestLogging(); |
| 77 | + |
70 | 78 | if (app.Environment.IsDevelopment()) |
71 | 79 | { |
72 | | - // https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle |
73 | 80 | app.UseSwagger(); |
74 | 81 | app.UseSwaggerUI(); |
75 | 82 | } |
76 | 83 |
|
77 | | -// https://github.com/serilog/serilog-aspnetcore |
78 | | -app.UseSerilogRequestLogging(); |
79 | | - |
80 | 84 | // https://learn.microsoft.com/en-us/aspnet/core/security/enforcing-ssl |
81 | 85 | app.UseHttpsRedirection(); |
82 | 86 |
|
|
0 commit comments