Phases 3 & 4: Complete data access architecture migration
Phase 3 — eliminated ApplicationDbContext from all non-exempt controllers, routing all data access through IUnitOfWork. Added IPlainRepository<T> for the four platform entities (Announcement, BannedIp, DashboardTip, ReleaseNote) that intentionally don't extend BaseEntity and therefore can't use the constrained IRepository<T>. Added permanent-exception comments to the 18 controllers that legitimately retain direct DbContext access (Identity infra, cross-tenant platform ops, bulk streaming exports). Phase 4 — added EnforceDataAccessArchitecture() to Program.cs, a startup gate that reflects over every Controller subclass and throws at boot if any non-exempt controller injects ApplicationDbContext. The app cannot start with a violation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,6 @@ using PowderCoating.Application.Services;
|
||||
using PowderCoating.Core.Entities;
|
||||
using PowderCoating.Core.Enums;
|
||||
using PowderCoating.Core.Interfaces;
|
||||
using PowderCoating.Infrastructure.Data;
|
||||
using PowderCoating.Shared.Constants;
|
||||
using System.Text.Json;
|
||||
|
||||
@@ -20,7 +19,6 @@ public class SetupWizardController : Controller
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly ITenantContext _tenantContext;
|
||||
private readonly UserManager<ApplicationUser> _userManager;
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly ISeedDataService _seedDataService;
|
||||
private readonly ILogger<SetupWizardController> _logger;
|
||||
|
||||
@@ -28,14 +26,12 @@ public class SetupWizardController : Controller
|
||||
IUnitOfWork unitOfWork,
|
||||
ITenantContext tenantContext,
|
||||
UserManager<ApplicationUser> userManager,
|
||||
ApplicationDbContext context,
|
||||
ISeedDataService seedDataService,
|
||||
ILogger<SetupWizardController> logger)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_tenantContext = tenantContext;
|
||||
_userManager = userManager;
|
||||
_context = context;
|
||||
_seedDataService = seedDataService;
|
||||
_logger = logger;
|
||||
}
|
||||
@@ -70,14 +66,14 @@ public class SetupWizardController : Controller
|
||||
if (company.Preferences == null)
|
||||
{
|
||||
company.Preferences = new CompanyPreferences { CompanyId = companyId };
|
||||
_context.Set<CompanyPreferences>().Add(company.Preferences);
|
||||
await _unitOfWork.CompanyPreferences.AddAsync(company.Preferences);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
}
|
||||
|
||||
if (company.OperatingCosts == null)
|
||||
{
|
||||
company.OperatingCosts = new CompanyOperatingCosts { CompanyId = companyId };
|
||||
_context.Set<CompanyOperatingCosts>().Add(company.OperatingCosts);
|
||||
await _unitOfWork.CompanyOperatingCosts.AddAsync(company.OperatingCosts);
|
||||
await _unitOfWork.CompleteAsync();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user