Introduce `EntitySelfMappingProfile` to enable self-mappings (T -> T) for domain entities (`EmailAccount`, `ReceivedEmail`, `EmailAttachment`). This ensures uniform AutoMapper usage in the generic repository, regardless of whether the target type is a DTO or the entity itself. Added necessary `using` directives for `AutoMapper` and domain entities.
74 lines
2.9 KiB
C#
74 lines
2.9 KiB
C#
using DigitalData.MessagingService.Application.Common.Interfaces;
|
|
using DigitalData.MessagingService.Application.Common.Interfaces.Repositories;
|
|
using DigitalData.MessagingService.Infrastructure.Persistence;
|
|
using DigitalData.MessagingService.Infrastructure.Queue;
|
|
using DigitalData.MessagingService.Infrastructure.Repositories;
|
|
using DigitalData.MessagingService.Infrastructure.Services;
|
|
using DigitalData.MessagingService.Infrastructure.Services.Background;
|
|
using DigitalData.MessagingService.Publisher;
|
|
using DigitalData.MessagingService.RabbitMQ;
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace DigitalData.MessagingService.Infrastructure;
|
|
|
|
/// <summary>
|
|
/// Dependency injection configuration for Infrastructure layer
|
|
/// </summary>
|
|
public static class DependencyInjection
|
|
{
|
|
/// <summary>
|
|
/// Adds Infrastructure layer services to the DI container
|
|
/// </summary>
|
|
public static IServiceCollection AddInfrastructure(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration)
|
|
{
|
|
// --- External Services ---
|
|
// Email Service - SMTP outbound (Limilabs Mail.dll)
|
|
services.AddSingleton<IEmailService, LimilabsEmailService>();
|
|
|
|
// Email Service - IMAP inbound (Limilabs Mail.dll)
|
|
// Fresh connection per call — stateless and thread-safe.
|
|
services.AddSingleton<IImapEmailService, LimilabsImapEmailService>();
|
|
|
|
// PDF Processing Service (using DevExpress.Pdf)
|
|
services.AddScoped<IPdfProcessingService, DevExpressPdfProcessingService>();
|
|
|
|
// Encryption Service (using Data Protection API - Singleton, thread-safe)
|
|
services.AddSingleton<IEncryptionService, DataProtectionEncryptionService>();
|
|
|
|
// --- Email Queue (RabbitMQ) ---
|
|
services.AddSingleton<SendingEmailConsumerPool>();
|
|
services.AddMessagingServicePublisher();
|
|
|
|
// --- RabbitMQ Configuration ---
|
|
services.AddRabbitMqConnectionFactory(configuration);
|
|
|
|
// --- Data Protection (for encryption) ---
|
|
services.AddDataProtection()
|
|
.PersistKeysToFileSystem(new DirectoryInfo(@"C:\ProgramData\EmailService\Keys"))
|
|
.SetApplicationName("MessagingService");
|
|
|
|
// Register Background Workers
|
|
services.AddHostedService<AsyncInitWorker>();
|
|
services.AddHostedService<EmailSyncWorker>();
|
|
|
|
services.AddMemoryCache();
|
|
|
|
// --- Database (InMemory) ---
|
|
services.AddDbContext<MessagingServiceDbContext>(options =>
|
|
options.UseInMemoryDatabase("MessagingServiceDb"));
|
|
|
|
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
|
|
|
|
// AutoMapper - Register entity self-mappings (T -> T) for generic repository
|
|
services.AddAutoMapper(config => config.AddMaps(typeof(EntitySelfMappingProfile).Assembly));
|
|
|
|
return services;
|
|
}
|
|
}
|
|
|