Refactor and enhance DbContext configuration
Updated `AddRecInfrastructure` to improve DbContext setup: - Renamed parameters for clarity (`dbContextOpt` to `opt`). - Renamed `connectionString` to `cnnStr` for consistency. - Added `LogTo` for SQL query logging at `Trace` level. - Enabled `EnableSensitiveDataLogging` for debugging. - Enabled `EnableDetailedErrors` for detailed error messages.
This commit is contained in:
parent
edf2468a33
commit
a7f4677ad1
@ -16,14 +16,14 @@ builder.Services.AddRecServices(options =>
|
||||
|
||||
builder.Services.AddRecInfrastructure(options =>
|
||||
{
|
||||
options.ConfigureDbContext((provider, dbContextOpt) =>
|
||||
options.ConfigureDbContext((provider, opt) =>
|
||||
{
|
||||
var connectionString = builder.Configuration.GetConnectionString("Default")
|
||||
var cnnStr = builder.Configuration.GetConnectionString("Default")
|
||||
?? throw new InvalidOperationException("Connection string is not found.");
|
||||
|
||||
var logger = provider.GetRequiredService<ILogger<RecDbContext>>();
|
||||
dbContextOpt.UseSqlServer(connectionString)
|
||||
.LogTo(log => logger.LogInformation("{log}", log), Microsoft.Extensions.Logging.LogLevel.Trace)
|
||||
opt.UseSqlServer(cnnStr)
|
||||
.LogTo(log => logger.LogInformation("{log}", log), LogLevel.Trace)
|
||||
.EnableSensitiveDataLogging()
|
||||
.EnableDetailedErrors();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user