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:
2025-10-01 13:25:52 +02:00
parent 9472322c1d
commit 82d4b7ec6a
3 changed files with 34 additions and 18 deletions

View File

@@ -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);
}
}
}
}