Strategic architecture, tactical design, and testable code principles (SOLID, Clean Architecture, Design Patterns, Testable Design)
97
97%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Passed
No known issues
Entities and use cases must never import framework-specific types. Framework dependencies in inner layers create tight coupling that makes testing slow and migration impossible.
Incorrect (use case imports framework types):
// Application/UseCases/ProcessPaymentUseCase.cs
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
public class ProcessPaymentUseCase
{
private readonly DbContext _context; // EF Core dependency
private readonly IHttpContextAccessor _http; // ASP.NET dependency
public async Task Execute(PaymentRequest request)
{
var userId = _http.HttpContext.User.Identity.Name;
var payment = JsonConvert.DeserializeObject<Payment>(request.Data);
_context.Payments.Add(payment);
await _context.SaveChangesAsync();
}
}Correct (use case depends only on abstractions):
// Application/UseCases/ProcessPaymentUseCase.cs
// No framework imports
public class ProcessPaymentUseCase
{
private readonly IPaymentRepository _payments;
private readonly ICurrentUserProvider _currentUser;
public async Task Execute(PaymentCommand command)
{
var userId = _currentUser.GetUserId();
var payment = new Payment(command.Amount, command.Currency, userId);
await _payments.Save(payment);
}
}
// Infrastructure/Persistence/EfPaymentRepository.cs
using Microsoft.EntityFrameworkCore;
public class EfPaymentRepository : IPaymentRepository
{
private readonly DbContext _context;
// Framework usage isolated to infrastructure
}Benefits:
Reference: Clean Architecture - Frameworks are Details
clean-architecture
evals
references
design-patterns
solid-principles
testable-design