Update DIExtensions for enhanced DbContext configuration
Modified the `AddEnvelopeGeneratorInfrastructureServices` method to accept a service provider, allowing for more complex DbContext configurations. Added a using directive for `Microsoft.Extensions.DependencyInjection` in `Program.cs`. Updated the method call to utilize the new signature, enabling logging of SQL commands and sensitive data during database operations.
This commit is contained in:
parent
456c591fae
commit
05867cc645
@ -33,7 +33,7 @@ public static class DIExtensions
|
||||
/// will be created per HTTP request (or per scope) within the dependency injection container.
|
||||
/// </remarks>
|
||||
public static IServiceCollection AddEnvelopeGeneratorInfrastructureServices(this IServiceCollection services,
|
||||
Action<DbContextOptionsBuilder>? dbContextOptions = null,
|
||||
Action<IServiceProvider, DbContextOptionsBuilder>? dbContextOptions = null,
|
||||
IConfiguration? sqlExecutorConfiguration = null,
|
||||
Action<SQLExecutorParams>? sqlExecutorConfigureOptions = null)
|
||||
{
|
||||
|
||||
@ -17,6 +17,8 @@ using EnvelopeGenerator.Web.Sanitizers;
|
||||
using EnvelopeGenerator.Application.Contracts.Services;
|
||||
using EnvelopeGenerator.Web.Models.Annotation;
|
||||
using DigitalData.UserManager.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
|
||||
var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
|
||||
logger.Info("Logging initialized!");
|
||||
@ -98,7 +100,13 @@ try
|
||||
});
|
||||
|
||||
// Add envelope generator services
|
||||
builder.Services.AddEnvelopeGeneratorInfrastructureServices(options => options.UseSqlServer(connStr));
|
||||
builder.Services.AddEnvelopeGeneratorInfrastructureServices((provider, options) =>
|
||||
{
|
||||
var logger = provider.GetRequiredService<ILogger<EGDbContext>>();
|
||||
options.UseSqlServer(connStr)
|
||||
.LogTo(log => logger.LogInformation("{log}", log), Microsoft.Extensions.Logging.LogLevel.Trace)
|
||||
.EnableSensitiveDataLogging();
|
||||
});
|
||||
|
||||
builder.Services.AddEnvelopeGeneratorServices(config);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user