feat(infrastructure): refactor DIExtensions for DbContext registration
* Removed `dbContextOptions` parameter from `AddEnvelopeGeneratorInfrastructureServices` * Moved `AddDbContext` registration into `Config` class with overloads for both `Action<DbContextOptionsBuilder>` and `Action<IServiceProvider, DbContextOptionsBuilder>` * Simplified service registration flow and improved extensibility
This commit is contained in:
parent
9472322c1d
commit
82d4b7ec6a
@ -185,7 +185,19 @@ try
|
|||||||
// Envelope generator serives
|
// Envelope generator serives
|
||||||
#pragma warning disable CS0618 // Type or member is obsolete
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
builder.Services
|
builder.Services
|
||||||
.AddEnvelopeGeneratorInfrastructureServices(sqlExecutorConfigureOptions: executor => executor.ConnectionString = connStr)
|
.AddEnvelopeGeneratorInfrastructureServices(opt =>
|
||||||
|
{
|
||||||
|
opt.ConfigureDbTriggerParams(config);
|
||||||
|
opt.AddDbContext((provider, options) =>
|
||||||
|
{
|
||||||
|
var logger = provider.GetRequiredService<ILogger<EGDbContext>>();
|
||||||
|
options.UseSqlServer(connStr)
|
||||||
|
.LogTo(log => logger.LogInformation("{log}", log), Microsoft.Extensions.Logging.LogLevel.Trace)
|
||||||
|
.EnableSensitiveDataLogging()
|
||||||
|
.EnableDetailedErrors();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
sqlExecutorConfigureOptions: executor => executor.ConnectionString = connStr)
|
||||||
.AddEnvelopeGeneratorServices(config);
|
.AddEnvelopeGeneratorServices(config);
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
|
|
||||||
|
|||||||
@ -39,12 +39,7 @@ namespace EnvelopeGenerator.Infrastructure
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
[Obsolete("Use IRepository")]
|
[Obsolete("Use IRepository")]
|
||||||
public static IServiceCollection AddEnvelopeGeneratorInfrastructureServices(this IServiceCollection services,
|
public static IServiceCollection AddEnvelopeGeneratorInfrastructureServices(this IServiceCollection services,
|
||||||
Action<Config> options,
|
Action<Config> options
|
||||||
Action<IServiceProvider, DbContextOptionsBuilder>
|
|
||||||
#if NET
|
|
||||||
?
|
|
||||||
#endif
|
|
||||||
dbContextOptions = null
|
|
||||||
#if NET
|
#if NET
|
||||||
, IConfiguration? sqlExecutorConfiguration = null,
|
, IConfiguration? sqlExecutorConfiguration = null,
|
||||||
Action<SQLExecutorParams>? sqlExecutorConfigureOptions = null
|
Action<SQLExecutorParams>? sqlExecutorConfigureOptions = null
|
||||||
@ -53,10 +48,6 @@ namespace EnvelopeGenerator.Infrastructure
|
|||||||
{
|
{
|
||||||
// configure custom options
|
// configure custom options
|
||||||
options(new Config(services));
|
options(new Config(services));
|
||||||
|
|
||||||
if (dbContextOptions != null)
|
|
||||||
services.AddDbContext<EGDbContext>(dbContextOptions);
|
|
||||||
|
|
||||||
#if NET
|
#if NET
|
||||||
services.TryAddScoped<IConfigRepository, ConfigRepository>();
|
services.TryAddScoped<IConfigRepository, ConfigRepository>();
|
||||||
services.TryAddScoped<IDocumentReceiverElementRepository, DocumentReceiverElementRepository>();
|
services.TryAddScoped<IDocumentReceiverElementRepository, DocumentReceiverElementRepository>();
|
||||||
@ -197,6 +188,16 @@ namespace EnvelopeGenerator.Infrastructure
|
|||||||
{
|
{
|
||||||
_services.Configure(configureOptions);
|
_services.Configure(configureOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddDbContext(Action<DbContextOptionsBuilder> dbContextOptions)
|
||||||
|
{
|
||||||
|
_services.AddDbContext<EGDbContext>(dbContextOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddDbContext(Action<IServiceProvider, DbContextOptionsBuilder> dbContextOptions)
|
||||||
|
{
|
||||||
|
_services.AddDbContext<EGDbContext>(dbContextOptions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,14 +104,17 @@ try
|
|||||||
// Add envelope generator services
|
// Add envelope generator services
|
||||||
#pragma warning disable CS0618 // Type or member is obsolete
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
builder.Services.AddEnvelopeGeneratorInfrastructureServices(
|
builder.Services.AddEnvelopeGeneratorInfrastructureServices(
|
||||||
opt => opt.ConfigureDbTriggerParams(config),
|
opt =>
|
||||||
(provider, options) =>
|
|
||||||
{
|
{
|
||||||
var logger = provider.GetRequiredService<ILogger<EGDbContext>>();
|
opt.ConfigureDbTriggerParams(config);
|
||||||
options.UseSqlServer(connStr)
|
opt.AddDbContext((provider, options) =>
|
||||||
.LogTo(log => logger.LogInformation("{log}", log), Microsoft.Extensions.Logging.LogLevel.Trace)
|
{
|
||||||
.EnableSensitiveDataLogging()
|
var logger = provider.GetRequiredService<ILogger<EGDbContext>>();
|
||||||
.EnableDetailedErrors();
|
options.UseSqlServer(connStr)
|
||||||
|
.LogTo(log => logger.LogInformation("{log}", log), Microsoft.Extensions.Logging.LogLevel.Trace)
|
||||||
|
.EnableSensitiveDataLogging()
|
||||||
|
.EnableDetailedErrors();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user