Use this skill when designing application structure or clarifying layer responsibilities in .NET applications.
When implementing Clean Architecture in .NET applications, follow these core principles:
Entity<T>, IAggregateRoot, domain eventsICommandHandler<T>, IQueryHandler<T, TResult>DbContext, IRepository<T>, IEmailService// Domain Entity
public abstract class Entity<T>
{
public T Id { get; protected set; }
public DateTime CreatedAt { get; protected set; }
// Domain logic methods
public void Validate() { /* business rules */ }
}
// Multi-tenant entity
public abstract class MultiTenantEntity : Entity<Guid>, ITenantEntity
{
public Guid TenantId { get; protected set; }
public bool BelongsToTenant(Guid tenantId) =>
TenantId == tenantId;
}
// Application layer interface
public interface IRepository<T> where T : Entity<Guid>
{
Task<T> GetByIdAsync(Guid id);
Task<IEnumerable<T>> GetAllAsync();
Task AddAsync(T entity);
Task UpdateAsync(T entity);
Task DeleteAsync(Guid id);
}
// Infrastructure implementation
public class Repository<T> : IRepository<T> where T : Entity<Guid>
{
private readonly GloboTicketDbContext _context;
// Implementation with EF Core
}
public class CreateVenueCommand : IRequest<VenueDto>
{
public string Name { get; set; }
public string Address { get; set; }
public Guid TenantId { get; set; }
}
public class CreateVenueCommandHandler :
IRequestHandler<CreateVenueCommand, VenueDto>
{
private readonly IVenueRepository _venueRepository;
private readonly IMapper _mapper;
public async Task<VenueDto> Handle(CreateVenueCommand request)
{
var venue = new Venue(request.Name, request.Address, request.TenantId);
await _venueRepository.AddAsync(venue);
return _mapper.Map<VenueDto>(venue);
}
}
GloboTicket.Domain/ - Domain entities and business logicGloboTicket.Application/ - Use cases, DTOs, interfacesGloboTicket.Infrastructure/ - EF Core, external servicesGloboTicket.API/ - Controllers, middleware, API endpointsThis architecture ensures maintainability, testability, and adherence to SOLID principles while providing clear separation of concerns.