From a7f4677ad151294b3f4599ad70d47e40491e9604 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 3 Dec 2025 11:48:23 +0100 Subject: [PATCH] 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. --- src/ReC.API/Program.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ReC.API/Program.cs b/src/ReC.API/Program.cs index 1887ee2..6b5cd81 100644 --- a/src/ReC.API/Program.cs +++ b/src/ReC.API/Program.cs @@ -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>(); - 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(); });