Files
DigitalData.MessagingService/src/infrastructure/DigitalData.MessagingService.Infrastructure/Persistence/MessagingServiceDbContext.cs
TekH 8b4d1e48f5 Add EmailAccountSyncWorker and configure EmailAccount entity
Introduced the `EmailAccountSyncWorker` background service to initialize and synchronize email accounts using RabbitMQ for event-driven processing. The service resolves email account configurations from application settings and upserts them into the repository.

Updated `MessagingServiceDbContext` to configure the `EmailAccount` entity, setting the `Username` property to use the `SQL_Latin1_General_CP1_CI_AS` collation for case-insensitive comparisons.

Added necessary `using` directives in `DependencyInjection.cs` to integrate new dependencies for AutoMapper, repositories, services, and background processing.
2026-08-13 09:37:39 +02:00

39 lines
1.3 KiB
C#

using DigitalData.MessagingService.Domain.Entities;
using Microsoft.EntityFrameworkCore;
namespace DigitalData.MessagingService.Infrastructure.Persistence;
/// <summary>
/// Entity Framework Core DbContext for MessagingService.
/// </summary>
public class MessagingServiceDbContext(DbContextOptions<MessagingServiceDbContext> options) : DbContext(options)
{
public DbSet<EmailAccount> EmailAccounts => Set<EmailAccount>();
public DbSet<ReceivedEmail> ReceivedEmails => Set<ReceivedEmail>();
public DbSet<EmailAttachment> EmailAttachments => Set<EmailAttachment>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<EmailAccount>(entity =>
{
entity.Property(e => e.Username)
.UseCollation("SQL_Latin1_General_CP1_CI_AS");
});
modelBuilder.Entity<ReceivedEmail>(entity =>
{
entity.HasMany(e => e.Attachments)
.WithOne(a => a.Email)
.HasForeignKey(a => a.EmailId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(e => e.Account)
.WithMany()
.HasForeignKey(e => e.AccountId)
.OnDelete(DeleteBehavior.Restrict);
});
}
}