|
2 | 2 | using Dotnet.Samples.AspNetCore.WebApi.Data; |
3 | 3 | using Dotnet.Samples.AspNetCore.WebApi.Mappings; |
4 | 4 | using Dotnet.Samples.AspNetCore.WebApi.Services; |
| 5 | +using Dotnet.Samples.AspNetCore.WebApi.Utilities; |
5 | 6 | using Microsoft.EntityFrameworkCore; |
6 | 7 | using Microsoft.OpenApi.Models; |
7 | 8 | using Serilog; |
|
20 | 21 | * Logging |
21 | 22 | * -------------------------------------------------------------------------- */ |
22 | 23 | Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(builder.Configuration).CreateLogger(); |
23 | | - |
24 | 24 | builder.Host.UseSerilog(); |
25 | 25 |
|
26 | 26 | /* ----------------------------------------------------------------------------- |
27 | 27 | * Services |
28 | 28 | * -------------------------------------------------------------------------- */ |
29 | | - |
30 | 29 | builder.Services.AddControllers(); |
31 | | - |
32 | | -var dataSource = |
33 | | - $"{AppDomain.CurrentDomain.SetupInformation.ApplicationBase}/Data/players-sqlite3.db"; |
34 | | - |
35 | 30 | builder.Services.AddDbContextPool<PlayerDbContext>(options => |
36 | 31 | { |
| 32 | + var dataSource = Path.Combine(AppContext.BaseDirectory, "Data", "players-sqlite3.db"); |
37 | 33 | options.UseSqlite($"Data Source={dataSource}"); |
38 | | - |
39 | 34 | if (builder.Environment.IsDevelopment()) |
40 | 35 | { |
41 | 36 | options.EnableSensitiveDataLogging(); |
42 | | - options.LogTo(Console.WriteLine, LogLevel.Information); |
| 37 | + options.LogTo(Log.Logger.Information, LogLevel.Information); |
| 38 | + // https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-9.0/whatsnew#improved-data-seeding |
| 39 | + options.UseAsyncSeeding(DbContextUtils.SeedAsync); |
43 | 40 | } |
44 | 41 | }); |
45 | 42 |
|
|
84 | 81 | * Middlewares |
85 | 82 | * https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware |
86 | 83 | * -------------------------------------------------------------------------- */ |
87 | | - |
88 | | -app.UseSerilogRequestLogging(); |
89 | | - |
90 | 84 | if (app.Environment.IsDevelopment()) |
91 | 85 | { |
92 | 86 | // https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle |
93 | 87 | app.UseSwagger(); |
94 | 88 | app.UseSwaggerUI(); |
95 | 89 | } |
96 | 90 |
|
| 91 | +// https://github.com/serilog/serilog-aspnetcore |
| 92 | +app.UseSerilogRequestLogging(); |
| 93 | + |
97 | 94 | // https://learn.microsoft.com/en-us/aspnet/core/security/enforcing-ssl |
98 | 95 | app.UseHttpsRedirection(); |
99 | 96 |
|
|
103 | 100 | // https://learn.microsoft.com/en-us/aspnet/core/fundamentals/routing#endpoints |
104 | 101 | app.MapControllers(); |
105 | 102 |
|
106 | | -/* ----------------------------------------------------------------------------- |
107 | | - * Data Seeding |
108 | | - * https://learn.microsoft.com/en-us/ef/core/modeling/data-seeding |
109 | | - * -------------------------------------------------------------------------- */ |
110 | | - |
111 | | -app.SeedDbContext(); |
112 | | - |
113 | 103 | await app.RunAsync(); |
0 commit comments