refactor(DependencyInjection.Config): add AddSQLExecutor method
This commit is contained in:
parent
82d4b7ec6a
commit
44a9971cf8
@ -187,7 +187,7 @@ try
|
||||
builder.Services
|
||||
.AddEnvelopeGeneratorInfrastructureServices(opt =>
|
||||
{
|
||||
opt.ConfigureDbTriggerParams(config);
|
||||
opt.AddDbTriggerParams(config);
|
||||
opt.AddDbContext((provider, options) =>
|
||||
{
|
||||
var logger = provider.GetRequiredService<ILogger<EGDbContext>>();
|
||||
@ -196,8 +196,8 @@ try
|
||||
.EnableSensitiveDataLogging()
|
||||
.EnableDetailedErrors();
|
||||
});
|
||||
},
|
||||
sqlExecutorConfigureOptions: executor => executor.ConnectionString = connStr)
|
||||
opt.AddSQLExecutor(executor => executor.ConnectionString = connStr);
|
||||
})
|
||||
.AddEnvelopeGeneratorServices(config);
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ using System;
|
||||
|
||||
namespace EnvelopeGenerator.Infrastructure
|
||||
{
|
||||
public static class DIExtensions
|
||||
public static class DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </remarks>
|
||||
[Obsolete("Use IRepository")]
|
||||
public static IServiceCollection AddEnvelopeGeneratorInfrastructureServices(this IServiceCollection services,
|
||||
Action<Config> options
|
||||
#if NET
|
||||
, IConfiguration? sqlExecutorConfiguration = null,
|
||||
Action<SQLExecutorParams>? sqlExecutorConfigureOptions = null
|
||||
#endif
|
||||
)
|
||||
public static IServiceCollection AddEnvelopeGeneratorInfrastructureServices(this IServiceCollection services, Action<Config> options)
|
||||
{
|
||||
// configure custom options
|
||||
options(new Config(services));
|
||||
@ -67,10 +61,8 @@ namespace EnvelopeGenerator.Infrastructure
|
||||
{
|
||||
// scan EnvelopeGenerator
|
||||
opt.RegisterFromAssembly<EGDbContext>(typeof(Config).Assembly);
|
||||
|
||||
// scan UserManager
|
||||
opt.RegisterFromAssembly<EGDbContext>(typeof(User).Assembly);
|
||||
|
||||
#if NET
|
||||
// scan EmailProfilerDispatcher
|
||||
opt.RegisterFromAssembly<EGDbContext>(typeof(EmailOut).Assembly);
|
||||
@ -94,9 +86,6 @@ namespace EnvelopeGenerator.Infrastructure
|
||||
services.AddScoped<IEnvelopeExecutor, EnvelopeExecutor>();
|
||||
services.AddScoped<IEnvelopeReceiverExecutor, EnvelopeReceiverExecutor>();
|
||||
services.AddScoped<IDocumentExecutor, DocumentExecutor>();
|
||||
|
||||
if (sqlExecutorConfiguration is not null || sqlExecutorConfigureOptions is not null)
|
||||
services.AddSQLExecutor(sqlExecutorConfiguration, sqlExecutorConfigureOptions);
|
||||
#endif
|
||||
|
||||
return services;
|
||||
@ -179,12 +168,12 @@ namespace EnvelopeGenerator.Infrastructure
|
||||
_services = services;
|
||||
}
|
||||
|
||||
public void ConfigureDbTriggerParams(IConfiguration configuration)
|
||||
public void AddDbTriggerParams(IConfiguration configuration)
|
||||
{
|
||||
_services.Configure<DbTriggerParams>(configuration.GetSection(nameof(DbTriggerParams)));
|
||||
}
|
||||
|
||||
public void ConfigureDbTriggerParams(Action<DbTriggerParams> configureOptions)
|
||||
public void AddDbTriggerParams(Action<DbTriggerParams> configureOptions)
|
||||
{
|
||||
_services.Configure(configureOptions);
|
||||
}
|
||||
@ -198,6 +187,26 @@ namespace EnvelopeGenerator.Infrastructure
|
||||
{
|
||||
_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
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,7 +106,7 @@ try
|
||||
builder.Services.AddEnvelopeGeneratorInfrastructureServices(
|
||||
opt =>
|
||||
{
|
||||
opt.ConfigureDbTriggerParams(config);
|
||||
opt.AddDbTriggerParams(config);
|
||||
opt.AddDbContext((provider, options) =>
|
||||
{
|
||||
var logger = provider.GetRequiredService<ILogger<EGDbContext>>();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user