I have a simple DDD service, with Article Aggregate root. I use MediatR and CQRS for separation of commands and queries. In DDD domain should not have dependencies on application and infrastructure layers. I have a repository IArticleRepository for composing some data from articles database. I have a rest endpoint for getting articles by some kind of filters so that I create
ArticleQuery : IRequest<ArticleDto(or Article)>
And when this query object should be? I have a repository per aggregate, so in Domain layer I have IArticleRepository. And I need to specify the input parameter type. If I put query in Infrastructure or Application layer I get the dependency from domain pointing to infrastructure or application. If I put query in Domain it violates DDD, because the query has no relations to business. If I will not putting an object, and just fields as a parameter to the repository, there will be about 10-15 parameters - this is a code smell.
It needed because in Query handler also appear SearchEngine logic, so I decided to encapsulate SQL logic from search engine logic in infrastructure via the repository or something like that.
* InfrastructureLowLevel (know nothing about higher levels)
- DatabaseImplementation
- IQuery[TResult]
.. can combine SQL for DB query, or invoke specific IRepository methods (override-able in IRepository)
- IRepository[TQuery, TResult]
methods:
\ TResult GetSingleByQueiry(TQuery IQuery)
\ List[TResult] GetMultiByQueiry(TQuery IQuery)
.. invokes DatabaseImplementation
.. invokes IQuery for specific actions - conditions by type