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:
@@ -39,12 +39,7 @@ namespace EnvelopeGenerator.Infrastructure
|
||||
/// </remarks>
|
||||
[Obsolete("Use IRepository")]
|
||||
public static IServiceCollection AddEnvelopeGeneratorInfrastructureServices(this IServiceCollection services,
|
||||
Action<Config> options,
|
||||
Action<IServiceProvider, DbContextOptionsBuilder>
|
||||
#if NET
|
||||
?
|
||||
#endif
|
||||
dbContextOptions = null
|
||||
Action<Config> options
|
||||
#if NET
|
||||
, IConfiguration? sqlExecutorConfiguration = null,
|
||||
Action<SQLExecutorParams>? sqlExecutorConfigureOptions = null
|
||||
@@ -53,10 +48,6 @@ namespace EnvelopeGenerator.Infrastructure
|
||||
{
|
||||
// configure custom options
|
||||
options(new Config(services));
|
||||
|
||||
if (dbContextOptions != null)
|
||||
services.AddDbContext<EGDbContext>(dbContextOptions);
|
||||
|
||||
#if NET
|
||||
services.TryAddScoped<IConfigRepository, ConfigRepository>();
|
||||
services.TryAddScoped<IDocumentReceiverElementRepository, DocumentReceiverElementRepository>();
|
||||
@@ -197,6 +188,16 @@ namespace EnvelopeGenerator.Infrastructure
|
||||
{
|
||||
_services.Configure(configureOptions);
|
||||
}
|
||||
|
||||
public void AddDbContext(Action<DbContextOptionsBuilder> dbContextOptions)
|
||||
{
|
||||
_services.AddDbContext<EGDbContext>(dbContextOptions);
|
||||
}
|
||||
|
||||
public void AddDbContext(Action<IServiceProvider, DbContextOptionsBuilder> dbContextOptions)
|
||||
{
|
||||
_services.AddDbContext<EGDbContext>(dbContextOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user