41 lines
1.9 KiB
C#
41 lines
1.9 KiB
C#
using Helpdesk.Application.Abstractions;
|
|||
|
|
using Helpdesk.Infrastructure.Background;
|
||
|
|
using Helpdesk.Infrastructure.Email;
|
||
|
|
using Helpdesk.Infrastructure.Persistence;
|
||
|
|
using Helpdesk.Infrastructure.Security;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
using Microsoft.Extensions.Configuration;
|
||
|
|
using Microsoft.Extensions.DependencyInjection;
|
||
|
|
|
||
|
|
namespace Helpdesk.Infrastructure;
|
||
|
|
|
||
|
|
public static class DependencyInjection
|
||
|
|
{
|
||
|
|
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
|
||
|
|
{
|
||
|
|
var connectionString = configuration.GetConnectionString("Helpdesk")
|
||
|
|
?? throw new InvalidOperationException("Chybí připojovací řetězec ConnectionStrings:Helpdesk.");
|
||
|
|
|
||
|
|
services.AddSingleton(TimeProvider.System);
|
||
|
|
services.Configure<JwtOptions>(configuration.GetSection(JwtOptions.Section));
|
||
|
|
services.Configure<EncryptionOptions>(configuration.GetSection(EncryptionOptions.Section));
|
||
|
|
|
||
|
|
services.AddSingleton<FieldEncryptor>();
|
||
|
|
services.AddSingleton<CreatedAtInterceptor>();
|
||
|
|
services.AddDbContext<HelpdeskDbContext>((sp, options) => options
|
||
|
|
.UseMySql(connectionString, new MariaDbServerVersion(new Version(11, 4)))
|
||
|
|
.UseSnakeCaseNamingConvention()
|
||
|
|
.AddInterceptors(sp.GetRequiredService<CreatedAtInterceptor>()));
|
||
|
|
services.AddScoped<IAppDbContext>(sp => sp.GetRequiredService<HelpdeskDbContext>());
|
||
|
|
|
||
|
|
services.AddSingleton<IPasswordHasher, BCryptPasswordHasher>();
|
||
|
|
services.AddSingleton<ITokenService, JwtTokenService>();
|
||
|
|
services.AddSingleton<IRevokedTokenStore, RevokedTokenStore>();
|
||
|
|
services.AddSingleton<IEmailSender, LoggingEmailSender>();
|
||
|
|
|
||
|
|
services.AddHostedService<RevokedTokenStoreLoader>();
|
||
|
|
services.AddHostedService<AdminSeeder>();
|
||
|
|
services.AddHostedService<AuthTokenCleanupService>();
|
||
|
|
return services;
|
||
|
|
}
|
||
|
|
}
|