POO Avancée & Architecture Logicielle avec C#
Injection par constructeur
public sealed class ReserveResourceHandler(
IReservationRepository repository,
IUnitOfWork unitOfWork,
IClock clock)
{
public async Task HandleAsync(ReserveResource command, CancellationToken ct)
{
var reservation = Reservation.Create(command.ResourceId, command.Start, command.End, clock.UtcNow);
await repository.AddAsync(reservation, ct);
await unitOfWork.SaveChangesAsync(ct);
}
}
- Les dépendances deviennent visibles.
- Le handler reste testable sans infrastructure réelle.