refactor(DependencyInjection.Config): add AddSQLExecutor method

This commit is contained in:
tekh 2025-10-01 14:08:41 +02:00
parent 82d4b7ec6a
commit 44a9971cf8
3 changed files with 28 additions and 19 deletions

View File

@ -187,7 +187,7 @@ try
builder.Services builder.Services
.AddEnvelopeGeneratorInfrastructureServices(opt => .AddEnvelopeGeneratorInfrastructureServices(opt =>
{ {
opt.ConfigureDbTriggerParams(config); opt.AddDbTriggerParams(config);
opt.AddDbContext((provider, options) => opt.AddDbContext((provider, options) =>
{ {
var logger = provider.GetRequiredService<ILogger<EGDbContext>>(); var logger = provider.GetRequiredService<ILogger<EGDbContext>>();
@ -196,8 +196,8 @@ try
.EnableSensitiveDataLogging() .EnableSensitiveDataLogging()
.EnableDetailedErrors(); .EnableDetailedErrors();
}); });
}, opt.AddSQLExecutor(executor => executor.ConnectionString = connStr);
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

View File

@ -21,7 +21,7 @@ using System;
namespace EnvelopeGenerator.Infrastructure namespace EnvelopeGenerator.Infrastructure
{ {
public static class DIExtensions public static class DependencyInjection
{ {
/// <summary> /// <summary>
/// Registers the required repositories for the Envelope Generator service to the given <see cref="IServiceCollection"/>. /// Registers the required repositories for the Envelope Generator service to the given <see cref="IServiceCollection"/>.
@ -38,13 +38,7 @@ namespace EnvelopeGenerator.Infrastructure
/// will be created per HTTP request (or per scope) within the dependency injection container. /// will be created per HTTP request (or per scope) within the dependency injection container.
/// </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
#if NET
, IConfiguration? sqlExecutorConfiguration = null,
Action<SQLExecutorParams>? sqlExecutorConfigureOptions = null
#endif
)
{ {
// configure custom options // configure custom options
options(new Config(services)); options(new Config(services));
@ -67,10 +61,8 @@ namespace EnvelopeGenerator.Infrastructure
{ {
// scan EnvelopeGenerator // scan EnvelopeGenerator
opt.RegisterFromAssembly<EGDbContext>(typeof(Config).Assembly); opt.RegisterFromAssembly<EGDbContext>(typeof(Config).Assembly);
// scan UserManager // scan UserManager
opt.RegisterFromAssembly<EGDbContext>(typeof(User).Assembly); opt.RegisterFromAssembly<EGDbContext>(typeof(User).Assembly);
#if NET #if NET
// scan EmailProfilerDispatcher // scan EmailProfilerDispatcher
opt.RegisterFromAssembly<EGDbContext>(typeof(EmailOut).Assembly); opt.RegisterFromAssembly<EGDbContext>(typeof(EmailOut).Assembly);
@ -94,9 +86,6 @@ namespace EnvelopeGenerator.Infrastructure
services.AddScoped<IEnvelopeExecutor, EnvelopeExecutor>(); services.AddScoped<IEnvelopeExecutor, EnvelopeExecutor>();
services.AddScoped<IEnvelopeReceiverExecutor, EnvelopeReceiverExecutor>(); services.AddScoped<IEnvelopeReceiverExecutor, EnvelopeReceiverExecutor>();
services.AddScoped<IDocumentExecutor, DocumentExecutor>(); services.AddScoped<IDocumentExecutor, DocumentExecutor>();
if (sqlExecutorConfiguration is not null || sqlExecutorConfigureOptions is not null)
services.AddSQLExecutor(sqlExecutorConfiguration, sqlExecutorConfigureOptions);
#endif #endif
return services; return services;
@ -179,12 +168,12 @@ namespace EnvelopeGenerator.Infrastructure
_services = services; _services = services;
} }
public void ConfigureDbTriggerParams(IConfiguration configuration) public void AddDbTriggerParams(IConfiguration configuration)
{ {
_services.Configure<DbTriggerParams>(configuration.GetSection(nameof(DbTriggerParams))); _services.Configure<DbTriggerParams>(configuration.GetSection(nameof(DbTriggerParams)));
} }
public void ConfigureDbTriggerParams(Action<DbTriggerParams> configureOptions) public void AddDbTriggerParams(Action<DbTriggerParams> configureOptions)
{ {
_services.Configure(configureOptions); _services.Configure(configureOptions);
} }
@ -198,6 +187,26 @@ namespace EnvelopeGenerator.Infrastructure
{ {
_services.AddDbContext<EGDbContext>(dbContextOptions); _services.AddDbContext<EGDbContext>(dbContextOptions);
} }
#if NET
public void AddSQLExecutor(IConfiguration configuration)
{
_services.Configure<SQLExecutorParams>(configuration);
_services.AddSingleton<ISQLExecutor, SQLExecutor>();
_services.AddSQLExecutor(configuration, null);
}
public void AddSQLExecutor(Action<SQLExecutorParams> options)
{
_services.Configure(options);
_services.AddSingleton<ISQLExecutor, SQLExecutor>();
_services.AddSQLExecutor(null, options);
}
#endif
} }
} }
} }

View File

@ -106,7 +106,7 @@ try
builder.Services.AddEnvelopeGeneratorInfrastructureServices( builder.Services.AddEnvelopeGeneratorInfrastructureServices(
opt => opt =>
{ {
opt.ConfigureDbTriggerParams(config); opt.AddDbTriggerParams(config);
opt.AddDbContext((provider, options) => opt.AddDbContext((provider, options) =>
{ {
var logger = provider.GetRequiredService<ILogger<EGDbContext>>(); var logger = provider.GetRequiredService<ILogger<EGDbContext>>();