When using Ardalis.Specification, the documentation mentions some benefits:
-
“Keep data access query logic in one place”
-
“Keep data access query logic in the domain layer”
This is fine, but I’m unsure if I should then create the necessary DTOs in the domain layer. It’s commonly said that you should only select the properties you wish to send back to the client.
If the Domain layer doesn’t reference any other layer and the Specification package requires setting the type, does it make this OK? Is there a better alternative?
public class StoresSpec : Specification<Store, StoreDto>
{
public StoresSpec()
{
Query.Select(x => new StoreDto(x.Name, x.Address));
}
}