Clean architecture
Keep business policies independent of infrastructure.
The problem and the pattern
The booking rule should not know which database or HTTP framework hosts it. Define required persistence operations inside the application boundary and implement them outside it. The composition root is allowed to know both sides so it can assemble the application.
Follow the flow
Make it concrete
This excerpt isolates the concept. Connect it to the booking API as you work through the exercise.
public interface IBookingStore
{
Task SaveAsync(Booking booking, CancellationToken ct);
}
// Domain and application projects do not reference EF Core.Trade-offs
- Dependency inversion makes adapters replaceable.
- Mapping between transport, application, and storage models costs code.
- Protect business rules first; do not add abstractions solely for hypothetical replacements.
When to avoid it
Avoid elaborate project splits in a small CRUD service when they obscure simple behavior without protecting rules.
Your turn
Which project owns IBookingStore, and why?
Reveal a worked answer
The application owns the contract because it describes what the use case needs. The infrastructure project implements it and references the application, reversing the usual dependency on storage details.