diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Extensions/AppServiceCollectionExtensions.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Extensions/AppServiceCollectionExtensions.cs index f3d6113..7831d77 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Extensions/AppServiceCollectionExtensions.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Extensions/AppServiceCollectionExtensions.cs @@ -37,7 +37,7 @@ public static class AppServiceCollectionExtensions public static IServiceCollection AddAppInfrastructure(this IServiceCollection services, IConfiguration configuration) { services.AddDatabaseInfrastructure(configuration); - services.AddPostgresDbContext(DatabaseConstants.AppDataSource); + services.AddPostgresDbContext(DatabaseConstants.AppDataSource); services.AddPostgresDbContext(DatabaseConstants.LogsDataSource); services.AddScoped(); diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/AppDataSeeder.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/AppDataSeeder.cs index 4bc9089..dda385e 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/AppDataSeeder.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/AppDataSeeder.cs @@ -36,7 +36,7 @@ public sealed class AppDataSeeder( } using var scope = serviceProvider.CreateScope(); - var appDbContext = scope.ServiceProvider.GetRequiredService(); + var appDbContext = scope.ServiceProvider.GetRequiredService(); var dictionaryDbContext = scope.ServiceProvider.GetRequiredService(); await EnsurePlatformTenantAsync(appDbContext, cancellationToken); @@ -52,7 +52,7 @@ public sealed class AppDataSeeder( /// /// 确保默认租户存在。 /// - private async Task EnsureDefaultTenantAsync(TakeoutAppDbContext dbContext, CancellationToken cancellationToken) + private async Task EnsureDefaultTenantAsync(TakeoutAdminDbContext dbContext, CancellationToken cancellationToken) { var tenantOptions = _options.DefaultTenant; if (tenantOptions == null || string.IsNullOrWhiteSpace(tenantOptions.Code) || string.IsNullOrWhiteSpace(tenantOptions.Name)) @@ -134,7 +134,7 @@ public sealed class AppDataSeeder( /// /// 确保平台租户存在。 /// - private async Task EnsurePlatformTenantAsync(TakeoutAppDbContext dbContext, CancellationToken cancellationToken) + private async Task EnsurePlatformTenantAsync(TakeoutAdminDbContext dbContext, CancellationToken cancellationToken) { var existingTenant = await dbContext.Tenants .IgnoreQueryFilters() diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/Repositories/TenantBillingRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/Repositories/TenantBillingRepository.cs index 7d8d382..aaad29e 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/Repositories/TenantBillingRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/Repositories/TenantBillingRepository.cs @@ -9,7 +9,7 @@ namespace TakeoutSaaS.Infrastructure.App.Persistence.Repositories; /// /// 租户账单仓储实现(EF Core)。 /// -public sealed class TenantBillingRepository(TakeoutAppDbContext context) : ITenantBillingRepository +public sealed class TenantBillingRepository(TakeoutAdminDbContext context) : ITenantBillingRepository { /// public async Task> SearchAsync( diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/Repositories/TenantPaymentRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/Repositories/TenantPaymentRepository.cs index d9ca04c..0e6a241 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/Repositories/TenantPaymentRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/Repositories/TenantPaymentRepository.cs @@ -9,7 +9,7 @@ namespace TakeoutSaaS.Infrastructure.App.Persistence.Repositories; /// /// 租户支付记录仓储实现(EF Core)。 /// -public sealed class TenantPaymentRepository(TakeoutAppDbContext context) : ITenantPaymentRepository +public sealed class TenantPaymentRepository(TakeoutAdminDbContext context) : ITenantPaymentRepository { /// public async Task> GetByBillingIdAsync(long billingStatementId, CancellationToken cancellationToken = default) diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/TakeoutAdminDbContext.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/TakeoutAdminDbContext.cs new file mode 100644 index 0000000..4871575 --- /dev/null +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/TakeoutAdminDbContext.cs @@ -0,0 +1,30 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.EntityFrameworkCore; +using TakeoutSaaS.Shared.Abstractions.Ids; +using TakeoutSaaS.Shared.Abstractions.Security; +using TakeoutSaaS.Shared.Abstractions.Tenancy; + +namespace TakeoutSaaS.Infrastructure.App.Persistence; + +/// +/// 管理端业务主库 DbContext:不启用租户全局过滤,用于跨租户查询与平台级任务。 +/// +public sealed class TakeoutAdminDbContext( + DbContextOptions options, + ITenantProvider tenantProvider, + ICurrentUserAccessor? currentUserAccessor = null, + IIdGenerator? idGenerator = null, + IHttpContextAccessor? httpContextAccessor = null) + : TakeoutAppDbContext(options, tenantProvider, currentUserAccessor, idGenerator, httpContextAccessor) +{ + /// + /// 配置实体映射关系(不启用租户过滤)。 + /// + /// 模型构建器。 + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + // 1. 构建基础模型(复用实体映射) + OnModelCreatingCore(modelBuilder); + } +} + diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/TakeoutAppDbContext.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/TakeoutAppDbContext.cs index 54ca514..37962a8 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/TakeoutAppDbContext.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Persistence/TakeoutAppDbContext.cs @@ -33,8 +33,8 @@ namespace TakeoutSaaS.Infrastructure.App.Persistence; /// /// 业务主库 DbContext。 /// -public sealed class TakeoutAppDbContext( - DbContextOptions options, +public class TakeoutAppDbContext( + DbContextOptions options, ITenantProvider tenantProvider, ICurrentUserAccessor? currentUserAccessor = null, IIdGenerator? idGenerator = null, @@ -382,10 +382,29 @@ public sealed class TakeoutAppDbContext( /// /// 模型构建器。 protected override void OnModelCreating(ModelBuilder modelBuilder) + { + // 1. 构建基础模型(软删除/注释 + 实体映射) + OnModelCreatingCore(modelBuilder); + + // 2. (空行后) 应用租户过滤 + ApplyTenantQueryFilters(modelBuilder); + } + + /// + /// 共享模型构建逻辑:软删除/注释 + 全部实体映射(不包含租户过滤)。 + /// + /// 模型构建器。 + protected void OnModelCreatingCore(ModelBuilder modelBuilder) { // 1. 调用基类配置 base.OnModelCreating(modelBuilder); - // 2. 配置全部实体映射 + + // 2. (空行后) 配置全部实体映射 + ConfigureModel(modelBuilder); + } + + internal static void ConfigureModel(ModelBuilder modelBuilder) + { ConfigureTenant(modelBuilder.Entity()); ConfigureMerchant(modelBuilder.Entity()); ConfigureStore(modelBuilder.Entity()); @@ -470,8 +489,6 @@ public sealed class TakeoutAppDbContext( ConfigureMetricDefinition(modelBuilder.Entity()); ConfigureMetricSnapshot(modelBuilder.Entity()); ConfigureMetricAlertRule(modelBuilder.Entity()); - - ApplyTenantQueryFilters(modelBuilder); } private static void ConfigureTenant(EntityTypeBuilder builder) diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfDeliveryRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfDeliveryRepository.cs index 3bc734d..9c75fb4 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfDeliveryRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfDeliveryRepository.cs @@ -12,7 +12,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// 初始化仓储。 /// -public sealed class EfDeliveryRepository(TakeoutAppDbContext context) : IDeliveryRepository +public sealed class EfDeliveryRepository(TakeoutAdminDbContext context) : IDeliveryRepository { /// public Task FindByIdAsync(long deliveryOrderId, long tenantId, CancellationToken cancellationToken = default) diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfInventoryRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfInventoryRepository.cs index 0cc6526..1ef37b9 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfInventoryRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfInventoryRepository.cs @@ -12,7 +12,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// 提供库存与批次的读写能力。 /// -public sealed class EfInventoryRepository(TakeoutAppDbContext context) : IInventoryRepository +public sealed class EfInventoryRepository(TakeoutAdminDbContext context) : IInventoryRepository { /// public Task FindByIdAsync(long inventoryItemId, long tenantId, CancellationToken cancellationToken = default) diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfMerchantCategoryRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfMerchantCategoryRepository.cs index f832908..681e99a 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfMerchantCategoryRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfMerchantCategoryRepository.cs @@ -8,7 +8,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// 商户类目的 EF Core 仓储实现。 /// -public sealed class EfMerchantCategoryRepository(TakeoutAppDbContext context) +public sealed class EfMerchantCategoryRepository(TakeoutAdminDbContext context) : IMerchantCategoryRepository { /// diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfMerchantRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfMerchantRepository.cs index 1a2454f..666211d 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfMerchantRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfMerchantRepository.cs @@ -14,7 +14,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// 初始化仓储。 /// -public sealed class EfMerchantRepository(TakeoutAppDbContext context, TakeoutLogsDbContext logsContext) : IMerchantRepository +public sealed class EfMerchantRepository(TakeoutAdminDbContext context, TakeoutLogsDbContext logsContext) : IMerchantRepository { /// public Task FindByIdAsync(long merchantId, long tenantId, CancellationToken cancellationToken = default) diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfOrderRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfOrderRepository.cs index ba663d4..0b117d7 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfOrderRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfOrderRepository.cs @@ -13,7 +13,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// 初始化仓储。 /// -public sealed class EfOrderRepository(TakeoutAppDbContext context) : IOrderRepository +public sealed class EfOrderRepository(TakeoutAdminDbContext context) : IOrderRepository { /// public Task FindByIdAsync(long orderId, long tenantId, CancellationToken cancellationToken = default) diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfPaymentRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfPaymentRepository.cs index 1b6ea8d..323656f 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfPaymentRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfPaymentRepository.cs @@ -12,7 +12,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// 初始化仓储。 /// -public sealed class EfPaymentRepository(TakeoutAppDbContext context) : IPaymentRepository +public sealed class EfPaymentRepository(TakeoutAdminDbContext context) : IPaymentRepository { /// public Task FindByIdAsync(long paymentId, long tenantId, CancellationToken cancellationToken = default) diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfProductRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfProductRepository.cs index 5b49b68..4e6d4c4 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfProductRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfProductRepository.cs @@ -14,7 +14,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// 初始化仓储。 /// -public sealed class EfProductRepository(TakeoutAppDbContext context) : IProductRepository +public sealed class EfProductRepository(TakeoutAdminDbContext context) : IProductRepository { /// public Task FindByIdAsync(long productId, long tenantId, CancellationToken cancellationToken = default) diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfQuotaPackageRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfQuotaPackageRepository.cs index 2e3e60e..d3226b9 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfQuotaPackageRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfQuotaPackageRepository.cs @@ -9,7 +9,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// EF 配额包仓储实现。 /// -public sealed class EfQuotaPackageRepository(TakeoutAppDbContext context) : IQuotaPackageRepository +public sealed class EfQuotaPackageRepository(TakeoutAdminDbContext context) : IQuotaPackageRepository { #region 配额包定义 diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfStatisticsRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfStatisticsRepository.cs index 694fdb7..14fae92 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfStatisticsRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfStatisticsRepository.cs @@ -9,7 +9,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// 统计数据仓储实现。 /// -public sealed class EfStatisticsRepository(TakeoutAppDbContext dbContext) : IStatisticsRepository +public sealed class EfStatisticsRepository(TakeoutAdminDbContext dbContext) : IStatisticsRepository { #region 订阅统计 diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfStoreRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfStoreRepository.cs index b8edc9c..45306cc 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfStoreRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfStoreRepository.cs @@ -14,7 +14,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// 初始化仓储。 /// -public sealed class EfStoreRepository(TakeoutAppDbContext context) : IStoreRepository +public sealed class EfStoreRepository(TakeoutAdminDbContext context) : IStoreRepository { /// public Task FindByIdAsync(long storeId, long tenantId, CancellationToken cancellationToken = default) diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfSubscriptionRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfSubscriptionRepository.cs index 5eca26d..75584c8 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfSubscriptionRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfSubscriptionRepository.cs @@ -10,7 +10,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// 订阅管理仓储实现。 /// -public sealed class EfSubscriptionRepository(TakeoutAppDbContext dbContext, TakeoutLogsDbContext logsContext) : ISubscriptionRepository +public sealed class EfSubscriptionRepository(TakeoutAdminDbContext dbContext, TakeoutLogsDbContext logsContext) : ISubscriptionRepository { #region 订阅查询 diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantAnnouncementReadRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantAnnouncementReadRepository.cs index 23236ae..af44e78 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantAnnouncementReadRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantAnnouncementReadRepository.cs @@ -8,7 +8,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// EF 公告已读仓储。 /// -public sealed class EfTenantAnnouncementReadRepository(TakeoutAppDbContext context) : ITenantAnnouncementReadRepository +public sealed class EfTenantAnnouncementReadRepository(TakeoutAdminDbContext context) : ITenantAnnouncementReadRepository { /// public Task> GetByAnnouncementAsync(long tenantId, long announcementId, CancellationToken cancellationToken = default) diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantAnnouncementRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantAnnouncementRepository.cs index 9249fd1..0480f7f 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantAnnouncementRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantAnnouncementRepository.cs @@ -9,7 +9,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// EF 租户公告仓储。 /// -public sealed class EfTenantAnnouncementRepository(TakeoutAppDbContext context) : ITenantAnnouncementRepository +public sealed class EfTenantAnnouncementRepository(TakeoutAdminDbContext context) : ITenantAnnouncementRepository { /// public async Task> SearchAsync( diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantNotificationRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantNotificationRepository.cs index 8738d6e..48794eb 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantNotificationRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantNotificationRepository.cs @@ -9,7 +9,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// EF 租户通知仓储。 /// -public sealed class EfTenantNotificationRepository(TakeoutAppDbContext context) : ITenantNotificationRepository +public sealed class EfTenantNotificationRepository(TakeoutAdminDbContext context) : ITenantNotificationRepository { /// public Task> SearchAsync( diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantPackageRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantPackageRepository.cs index ad9e266..2e16c76 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantPackageRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantPackageRepository.cs @@ -9,7 +9,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// 租户套餐仓储实现。 /// -public sealed class EfTenantPackageRepository(TakeoutAppDbContext context) : ITenantPackageRepository +public sealed class EfTenantPackageRepository(TakeoutAdminDbContext context) : ITenantPackageRepository { /// public Task FindByIdAsync(long id, CancellationToken cancellationToken = default) diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantQuotaUsageHistoryRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantQuotaUsageHistoryRepository.cs index 701cbff..30957bd 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantQuotaUsageHistoryRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantQuotaUsageHistoryRepository.cs @@ -7,7 +7,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// 租户配额使用历史仓储实现。 /// -public sealed class EfTenantQuotaUsageHistoryRepository(TakeoutAppDbContext context) : ITenantQuotaUsageHistoryRepository +public sealed class EfTenantQuotaUsageHistoryRepository(TakeoutAdminDbContext context) : ITenantQuotaUsageHistoryRepository { /// public Task AddAsync(TenantQuotaUsageHistory history, CancellationToken cancellationToken = default) diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantQuotaUsageRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantQuotaUsageRepository.cs index dd9c564..b11971e 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantQuotaUsageRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantQuotaUsageRepository.cs @@ -9,7 +9,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// 租户配额使用仓储实现。 /// -public sealed class EfTenantQuotaUsageRepository(TakeoutAppDbContext context) : ITenantQuotaUsageRepository +public sealed class EfTenantQuotaUsageRepository(TakeoutAdminDbContext context) : ITenantQuotaUsageRepository { /// public Task FindAsync(long tenantId, TenantQuotaType quotaType, CancellationToken cancellationToken = default) diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantRepository.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantRepository.cs index 8e5c4f9..307d80c 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantRepository.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Repositories/EfTenantRepository.cs @@ -11,7 +11,7 @@ namespace TakeoutSaaS.Infrastructure.App.Repositories; /// /// 租户聚合的 EF Core 仓储实现。 /// -public sealed class EfTenantRepository(TakeoutAppDbContext context, TakeoutLogsDbContext logsContext) : ITenantRepository +public sealed class EfTenantRepository(TakeoutAdminDbContext context, TakeoutLogsDbContext logsContext) : ITenantRepository { /// public Task FindByIdAsync(long tenantId, CancellationToken cancellationToken = default) diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Services/StoreSchedulerService.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Services/StoreSchedulerService.cs index 7a183ff..ace6afc 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Services/StoreSchedulerService.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/App/Services/StoreSchedulerService.cs @@ -11,7 +11,7 @@ namespace TakeoutSaaS.Infrastructure.App.Services; /// 门店定时任务服务实现。 /// public sealed class StoreSchedulerService( - TakeoutAppDbContext context, + TakeoutAdminDbContext context, ILogger logger) : IStoreSchedulerService { diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/BackgroundServices/AutoRenewalService.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/BackgroundServices/AutoRenewalService.cs index 9eb39db..2fa69fe 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/BackgroundServices/AutoRenewalService.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/BackgroundServices/AutoRenewalService.cs @@ -68,7 +68,7 @@ public sealed class AutoRenewalService : BackgroundService _logger.LogInformation("开始处理自动续费"); using var scope = _serviceProvider.CreateScope(); - var dbContext = scope.ServiceProvider.GetRequiredService(); + var dbContext = scope.ServiceProvider.GetRequiredService(); var idGenerator = scope.ServiceProvider.GetRequiredService(); var now = DateTime.UtcNow; diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/BackgroundServices/RenewalReminderService.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/BackgroundServices/RenewalReminderService.cs index ced3034..a9acd90 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/BackgroundServices/RenewalReminderService.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/BackgroundServices/RenewalReminderService.cs @@ -68,7 +68,7 @@ public sealed class RenewalReminderService : BackgroundService _logger.LogInformation("开始发送续费提醒"); using var scope = _serviceProvider.CreateScope(); - var dbContext = scope.ServiceProvider.GetRequiredService(); + var dbContext = scope.ServiceProvider.GetRequiredService(); var idGenerator = scope.ServiceProvider.GetRequiredService(); var now = DateTime.UtcNow; diff --git a/src/Infrastructure/TakeoutSaaS.Infrastructure/BackgroundServices/SubscriptionExpiryCheckService.cs b/src/Infrastructure/TakeoutSaaS.Infrastructure/BackgroundServices/SubscriptionExpiryCheckService.cs index a743e66..0b62cb0 100644 --- a/src/Infrastructure/TakeoutSaaS.Infrastructure/BackgroundServices/SubscriptionExpiryCheckService.cs +++ b/src/Infrastructure/TakeoutSaaS.Infrastructure/BackgroundServices/SubscriptionExpiryCheckService.cs @@ -66,7 +66,7 @@ public sealed class SubscriptionExpiryCheckService : BackgroundService _logger.LogInformation("开始执行订阅到期检查"); using var scope = _serviceProvider.CreateScope(); - var dbContext = scope.ServiceProvider.GetRequiredService(); + var dbContext = scope.ServiceProvider.GetRequiredService(); var now = DateTime.UtcNow; var gracePeriodDays = _options.GracePeriodDays; diff --git a/tests/TakeoutSaaS.Integration.Tests/Fixtures/SqliteTestDatabase.cs b/tests/TakeoutSaaS.Integration.Tests/Fixtures/SqliteTestDatabase.cs index c87c19a..2b811ee 100644 --- a/tests/TakeoutSaaS.Integration.Tests/Fixtures/SqliteTestDatabase.cs +++ b/tests/TakeoutSaaS.Integration.Tests/Fixtures/SqliteTestDatabase.cs @@ -13,18 +13,18 @@ public sealed class SqliteTestDatabase : IDisposable { _connection = new SqliteConnection("Filename=:memory:"); _connection.Open(); - Options = new DbContextOptionsBuilder() + Options = new DbContextOptionsBuilder() .UseSqlite(_connection) .EnableSensitiveDataLogging() .Options; } - public DbContextOptions Options { get; } + public DbContextOptions Options { get; } - public TakeoutAppDbContext CreateContext(long tenantId, long userId = 0) + public TakeoutAdminDbContext CreateContext(long tenantId, long userId = 0) { EnsureCreated(); - return new TakeoutAppDbContext(Options, new TestTenantProvider(tenantId), new TestCurrentUserAccessor(userId)); + return new TakeoutAdminDbContext(Options, new TestTenantProvider(tenantId), new TestCurrentUserAccessor(userId)); } public void EnsureCreated() @@ -34,7 +34,7 @@ public sealed class SqliteTestDatabase : IDisposable return; } - using var context = new TakeoutAppDbContext(Options, new TestTenantProvider(1)); + using var context = new TakeoutAdminDbContext(Options, new TestTenantProvider(1)); context.Database.EnsureCreated(); _initialized = true; }