using InboxIntel.Application.Abstractions; using InboxIntel.Domain.Common; using InboxIntel.Domain.Entities; using Microsoft.EntityFrameworkCore; using System.Reflection; namespace InboxIntel.Infrastructure.Persistence; public class AppDbContext : DbContext, IAppDbContext { private readonly ICurrentUser? _currentUser; public AppDbContext(DbContextOptions options, ICurrentUser? currentUser = null) : base(options) => _currentUser = currentUser; /// /// Tenant id used by the global query filters below. Resolves to the /// authenticated user during an HTTP request. It is /// when there is no current user (background workers, design-time tooling, /// startup migration) — in which case filtering is DISABLED, because those /// paths are trusted server code that already scope their own queries by a /// userId passed in explicitly. The security value is on the HTTP attack /// surface: a forgotten manual WHERE UserId == can no longer leak /// another tenant's rows, since the filter restricts to the caller. /// public Guid CurrentUserId => _currentUser?.UserId ?? Guid.Empty; public DbSet Users => Set(); public DbSet Emails => Set(); public DbSet Threads => Set(); public DbSet Senders => Set(); public DbSet Domains => Set(); public DbSet Attachments => Set(); public DbSet