I am learning ASP.NET clean architecture structure. I have an application layer with a query GetAllRestaurants which has to return paginated restaurant objects.
I am using repository pattern, with the structure as shown in this screenshot:
Now, I want to create an endpoint which takes GetRestaurantQuery [FromBody], which is a class in the application layer, then passes this object to the RestaurantRepository and returns PagedResult object.
My problem is that the domain layer has no access to any other layers.
So in IRestaurantRepository, I cannot define any method that uses DTOs or objects from the application layer.
This is the Handle method from my application layer:
public async Task<PagedResult<List<RestaurantDto>>> Handle(GetRestaurantQuery request, CancellationToken cancellationToken)
{
var restaurants = await _restaurantRepository.GetAllRestaurants(request);
// etc...
}
And my IRestaurantRepository is trying to use those DTOs:
using Domain.Entities;
namespace Domain.Repository
{
public interface IRestaurantRepository
{
Task<PagedResult<List<Restaurant>>> GetAllRestaurants(GetRestaurantQuery query); <----
Task<Restaurant> GetRestaurantById(int Id);
Task<int> CreateRestaurant(Restaurant restaurant);
}
}
which obviously is not working, because the domain layer has no access.
What is the best way to handle such situation?
I thought about:
- removing repository layer (but I still want to know how I should handle this)
- passing primitive types to
IRestaurantRepositorymethods, then return primitive types as well and construct objects in application layer. But that seems wrong.
So how should I handle that? Thanks in advance.
