72 lines
2.9 KiB
C#
72 lines
2.9 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SPMS.Application.Interfaces;
|
|
using SPMS.Application.Settings;
|
|
using SPMS.Domain.Interfaces;
|
|
using SPMS.Infrastructure.Auth;
|
|
using SPMS.Infrastructure.Messaging;
|
|
using SPMS.Infrastructure.Persistence;
|
|
using SPMS.Infrastructure.Push;
|
|
using SPMS.Infrastructure.Persistence.Repositories;
|
|
using SPMS.Infrastructure.Security;
|
|
using SPMS.Infrastructure.Services;
|
|
|
|
namespace SPMS.Infrastructure;
|
|
|
|
public static class DependencyInjection
|
|
{
|
|
public static IServiceCollection AddInfrastructure(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration)
|
|
{
|
|
// DbContext
|
|
var connectionString = configuration.GetConnectionString("DefaultConnection");
|
|
services.AddDbContext<AppDbContext>(options =>
|
|
options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)));
|
|
|
|
// UnitOfWork & Repositories
|
|
services.AddScoped<IUnitOfWork, UnitOfWork>();
|
|
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
|
|
services.AddScoped<IServiceRepository, ServiceRepository>();
|
|
services.AddScoped<IAdminRepository, AdminRepository>();
|
|
services.AddScoped<INoticeRepository, NoticeRepository>();
|
|
services.AddScoped<IBannerRepository, BannerRepository>();
|
|
services.AddScoped<IFaqRepository, FaqRepository>();
|
|
services.AddScoped<IAppConfigRepository, AppConfigRepository>();
|
|
services.AddScoped<IDeviceRepository, DeviceRepository>();
|
|
services.AddScoped<IFileRepository, FileRepository>();
|
|
services.AddScoped<IMessageRepository, MessageRepository>();
|
|
|
|
// External Services
|
|
services.AddScoped<IJwtService, JwtService>();
|
|
services.AddSingleton<IE2EEService, E2EEService>();
|
|
services.AddSingleton<ICredentialEncryptionService, CredentialEncryptionService>();
|
|
|
|
// File Storage
|
|
services.AddSingleton<IFileStorageService, LocalFileStorageService>();
|
|
|
|
// RabbitMQ
|
|
services.Configure<RabbitMQSettings>(configuration.GetSection(RabbitMQSettings.SectionName));
|
|
services.AddSingleton<RabbitMQConnection>();
|
|
services.AddHostedService<RabbitMQInitializer>();
|
|
services.AddScoped<IPushQueueService, PushQueueService>();
|
|
|
|
// Push Senders
|
|
services.AddSingleton<IFcmSender, FcmSender>();
|
|
services.AddHttpClient("ApnsSender")
|
|
.ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler
|
|
{
|
|
EnableMultipleHttp2Connections = true
|
|
});
|
|
services.AddSingleton<IApnsSender, ApnsSender>();
|
|
|
|
// Token Store & Email Service
|
|
services.AddMemoryCache();
|
|
services.AddSingleton<ITokenStore, InMemoryTokenStore>();
|
|
services.AddSingleton<IEmailService, ConsoleEmailService>();
|
|
|
|
return services;
|
|
}
|
|
}
|