Clean Architecture & Layer Boundaries
Clean Architecture in the EricksonLopez ecosystem enforces a strict, compiler-verified unidirectional dependency graph so business invariants remain independent of databases, web frameworks, and transport brokers.
Presentation / API ──▶ Application ──▶ Domain │ ▲ └──▶ Infrastructure ─┘- Domain (
EricksonLopez.SharedKernel,EricksonLopez.DomainPrimitives,EricksonLopez.ValueObjects,EricksonLopez.Result): Entities, Aggregate Roots, Value Objects, Strongly-Typed IDs, Domain Events, and domain invariants. Zero references to EF Core, Dapper, ASP.NET Core, or JSON serializers. - Application (
EricksonLopez.Mediator,EricksonLopez.Specification,EricksonLopez.Idempotency.Abstractions): Use cases, commands/queries, port interfaces, and validation pipelines. Depends only on Domain and abstractions. - Infrastructure (
EricksonLopez.DapperExtensions,EricksonLopez.Outbox,EricksonLopez.Security): Concrete repositories, raw SQL queries, cryptographic providers, and external clients implementing Application ports. - Presentation (
EricksonLopez.Result.AspNetCore,EricksonLopez.Result.OpenApi): Minimal APIs, endpoint filters, ProblemDetails mapping, and authentication filters with zero business logic.
Notice that <ImplicitUsings>disable</ImplicitUsings> is mandatory across all projects, non-generic Result is returned when an operation produces no payload, and [StrongId<Guid>] generates the strongly-typed ID at compile time:
using System;using System.Threading;using System.Threading.Tasks;using EricksonLopez.DomainPrimitives;using EricksonLopez.Result;using EricksonLopez.SharedKernel;
namespace Example.CleanArchitecture.Orders;
[StrongId<Guid>]public readonly partial record struct CustomerId;
public interface ICustomerRepository{ ValueTask<bool> ExistsAsync(CustomerId id, CancellationToken cancellationToken); ValueTask SaveAsync(Customer customer, CancellationToken cancellationToken);}
public sealed class Customer : AggregateRoot<CustomerId>{ public string LegalName { get; private set; }
private Customer(CustomerId id, string legalName) : base(id) { LegalName = legalName; }
public static Result<Customer> Register(CustomerId id, string legalName) { if (string.IsNullOrWhiteSpace(legalName)) { return Result.Failure<Customer>( Error.Validation("Customer.EmptyName", "Legal name is required.")); }
return Result.Success(new Customer(id, legalName.Trim())); }
public Result Rename(string updatedName) { if (string.IsNullOrWhiteSpace(updatedName)) { return Result.Failure( Error.Validation("Customer.EmptyName", "Legal name cannot be empty.")); }
LegalName = updatedName.Trim(); return Result.Success(); }}