I checked out these posts, but didn't find an appropriate answer:
CQRS: Read model built on demand?
CQRS: business logic on the query side
I got stuck with my architecture based on CQRS. I understand that the query side should have a thin data access layer, but in my project I need to adjust the query based on metadata coming from other domain objects.
In several articles on the internet there is one table per view in the report database. So a SQL command like 'SELECT * FROM Tablename WHERE...' is all you need. This is not suitable here because the columns returned by the query should be customizable (through a column filter).
This should work as follows:
- Query is invoked by client, containing a filter id for rows (the WHERE part) and another filter id for columns (the SELECT part).
- The QueryHandler builds an SQL-query based on information extracted from a domain service based on the ids of the two filters
- Query is executed against the database and the result is returned to the client
What I'm struggling with is the dependency on the domain service in step 2. For me it feels as this shouldn't be, due to separation between query and command side.
Is this an acceptable way to deal with this problem or is there another approach that separates the two sides?