8 slides · software engineering
.NET Best Practices.
The expectation.
The reality.
Everyone talks about Clean Architecture, CQRS, and DDD.
But most teams are still writing God-class controllers
and calling it "enterprise-grade."
✦ Expectation (best practice)
4 strict layers
✗ Reality (what teams actually do)
One mega project
// ✦ Clean Architecture Solution/ ├── Domain/ │ ├── Entities/ │ └── Events/ ├── Application/ │ ├── Commands/ │ ├── Queries/ │ └── Interfaces/ ├── Infrastructure/ │ ├── Repositories/ │ └── Persistence/ └── API/ └── Controllers/ // Each layer has ONE job. // Dependency only flows inward.
// ✗ What most teams ship MyProject/ ├── Controllers/ │ └── OrderController.cs │ // 600 lines │ // calls DbContext directly │ // sends emails here too │ // validates input here │ // maps DTOs here │ // logs here │ // handles errors here ├── Models/ └── Data/ └── AppDbContext.cs
// ✦ CQRS done right public record CreateOrderCommand(string CustomerId, decimal Total) : IRequest<Guid>; public class CreateOrderHandler : IRequestHandler<CreateOrderCommand, Guid> { public async Task<Guid> Handle(CreateOrderCommand cmd, CancellationToken ct) { var order = Order.Create(cmd.CustomerId, cmd.Total); // domain logic await _repo.AddAsync(order, ct); return order.Id; // clean. testable. single responsibility. ✦ } }
Order.Create() enforces invariants.if (order.Total < 0) written 6 times across the codebase.// ✦ Rich Domain Entity public class Order { private Order() {} // no public ctor public static Order Create( string customerId, Money total) { ArgumentException.ThrowIfNullOrEmpty( customerId); if (total.Amount <= 0) throw new DomainException( "Total must be positive"); return new Order { ... }; } }
// ✗ Anemic model (common reality) public class Order { public int Id { get; set; } public string CustomerId { get; set; } public decimal Total { get; set; } public string Status { get; set; } // anyone can set anything // no invariants enforced // validation lives elsewhere // (or nowhere) }
catch (Exception ex) {}Console.WriteLine(ex.Message) as "logging."// ✦ Result pattern public async Task<Result<Guid>> Handle(CreateOrderCommand cmd) { var customer = await _repo.FindAsync(cmd.CustomerId); if (customer is null) return Result.Fail( "Customer not found"); var order = Order.Create(customer, ...); await _repo.AddAsync(order); return Result.Ok(order.Id); }
// ✗ Exception-driven reality public async Task<IActionResult> Create(OrderDto dto) { try { var order = new Order(); order.CustomerId = dto.CustomerId; _db.Orders.Add(order); await _db.SaveChangesAsync(); return Ok("success"); // 200 always } catch (Exception ex) { return Ok(new { error = ex.Message }); // still 200. still wrong. 💀 } }
Best practices are a compass,
not a religion.
The engineers who copy Clean Architecture templates into every project without understanding why — are just creating a different kind of mess.
When CQRS makes sense
Complex domain. Different read/write load. Multiple bounded contexts. Enterprise scale. Audit trail needed.
When CQRS is overkill
Simple CRUD API. 3-person startup. MVP with 5 endpoints. When the ceremony costs more than the benefit.
The mark of a senior engineer is not knowing every pattern.
It's knowing which pattern fits which problem — and having the confidence to say "we don't need that here."
Rais Helmy Sapiullah
Senior .NET · FlutterFlow · Solution Architect · Cloudflare
I build enterprise .NET systems that are actually maintainable — not just architecturally impressive templates. 6+ years across insurance, defence, utility, and ERP in Malaysia.