โ .NET Web API Architecture & Quality Checklist
This checklist defines the architectural requirements, code quality rules, and engineering standards for the InventoryAlert codebase.
๐๏ธ 1. Architecture & Layer Disciplineโ
- Layer Boundaries:
InventoryAlert.Domainhas zero imports from Application, Infrastructure, or Web layers. - Primary Constructors: C# 12 primary constructors are used for dependency injection across services and repositories.
- No Async Without Await: Methods returning
Taskwithout async operations returnTask.FromResult(...)directly (noCS1998warnings). - Cancellation Tokens:
CancellationToken ctis the last parameter in every service and repository method.
๐๏ธ 2. Entity Framework Core & Transactionsโ
- Transaction Capture Pattern: Every multi-write operation uses
_unitOfWork.ExecuteTransactionAsyncwith result assignment inside the lambda:AlertRuleResponse result = null!;await _unitOfWork.ExecuteTransactionAsync(async () => {var updated = await _repo.UpdateAsync(entity);result = MapToResponse(updated);}, ct);return result; - Read-Only Queries: All read-only EF Core LINQ queries specify
.AsNoTracking(). - No Direct DbContext Injections: Services inject
IUnitOfWorkor specific repositories, neverAppDbContextdirectly.
๐งช 3. Unit & Integration Testing Standardsโ
- Test Coverage: Happy path, not found, and transaction execution counts are verified for all service methods.
- Mock Delegate Invocation:
ExecuteTransactionAsyncmocks invoke the delegate parameter:_uowMock.Setup(u => u.ExecuteTransactionAsync(It.IsAny<Func<Task>>(), It.IsAny<CancellationToken>())).Returns<Func<Task>, CancellationToken>((action, _) => action()); - Zero Thread.Sleep: No
Thread.Sleepcalls allowed in test suites.
๐ 4. API Response Standards & Error Handlingโ
- Global Error Middleware:
GlobalExceptionMiddlewarecatchesUserFriendlyExceptionand returns standardized problem details JSON:{"status": 404,"title": "NotFound","detail": "Stock listing for 'INVALID' was not found."} - Thin Controllers: Controllers contain no business logic; they delegate directly to Application-layer services.