This commit replaces the `AddEnvelopeGeneratorRepositories` method with `AddEnvelopeGeneratorInfrastructureServices`, allowing for more flexible configuration through `IConfiguration` and `Action<SQLExecutorParams>`. The `SQLExecutor` class now utilizes `SQLExecutorParams` for its connection string, enhancing configurability. A new `SQLExecutorParams` class has been introduced to encapsulate connection string management. Various service registration calls have been updated to integrate the new infrastructure services, improving modularity and ease of database connection management.
56 lines
2.2 KiB
C#
56 lines
2.2 KiB
C#
using CommandDotNet.NameCasing;
|
|
using CommandDotNet;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using CommandDotNet.IoC.MicrosoftDependencyInjection;
|
|
using EnvelopeGenerator.Infrastructure;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using EnvelopeGenerator.Application.Contracts.Services;
|
|
using EnvelopeGenerator.Application.Services;
|
|
using Microsoft.Extensions.Hosting;
|
|
using EnvelopeGenerator.Application;
|
|
|
|
namespace EnvelopeGenerator.Terminal;
|
|
|
|
public static class DependencyInjection
|
|
{
|
|
public static IServiceCollection AddCommandManagerRunner(this IServiceCollection services, IConfiguration configuration, Case @case = Case.KebabCase, string connectionStringKeyName = "Default")
|
|
{
|
|
var connStr = configuration.GetConnectionString(connectionStringKeyName)
|
|
?? throw new InvalidOperationException("There is no default connection string in appsettings.json.");
|
|
|
|
services.AddDistributedSqlServerCache(options =>
|
|
{
|
|
options.ConnectionString = connStr;
|
|
options.SchemaName = "dbo";
|
|
options.TableName = "TBDD_CACHE";
|
|
});
|
|
|
|
// Add envelope generator services
|
|
services.AddEnvelopeGeneratorInfrastructureServices(options => options.UseSqlServer(connStr));
|
|
|
|
return services
|
|
.AddSingleton<CommandManager>()
|
|
.AddEnvelopeGeneratorInfrastructureServices()
|
|
.AddEnvelopeGeneratorServices(configuration)
|
|
.AddSingleton(sp =>
|
|
{
|
|
var runner = new AppRunner<CommandManager>();
|
|
runner.UseMicrosoftDependencyInjection(sp);
|
|
runner.UseNameCasing(@case);
|
|
return runner;
|
|
})
|
|
.AddScoped<IEnvelopeMailService, EnvelopeMailService>()
|
|
.AddMemoryCache()
|
|
.AddLocalization();
|
|
}
|
|
|
|
public static Task<int> RunCommandManagerRunner(this IServiceProvider provider, string[] args)
|
|
{
|
|
var runner = provider.GetRequiredService<AppRunner<CommandManager>>();
|
|
return runner.RunAsync(args);
|
|
}
|
|
|
|
public static Task<int> RunCommandManagerRunner(this IHost host, string[] args) => host.Services.RunCommandManagerRunner(args);
|
|
}
|