I thinking about writing an app using an onion/hexagonal architecture pattern. I'm stuck on a database externalization.
My app need to make some complex data queries to fulfill a use cases. I have two aggregates "A" and "B" and they are related. To fulfill UseCase1 I need to get all "A"s having properties wich match given values and additionaly related to "B"s having properties which match other values. To fulfill UseCase2 I need to do some other "query". I plan to create a repository interface f.e. ARepository which will isolate database access details from the domain logic. Since filter rules are domain rules they cannot be an implementation detail of repository class.
My doubts:
- Is it ok that ARepository implementation makes some SQL joins to "B" tables?
- Is it ok to design some generic filter criteria object and each UseCase will create own criteria and use it to pass to ARepository::filterByCriteria()? Is it a good contract?
- Is it ok to create dedicated methods in ARepository for each UseCase? (I'm affraid that in the future there will be plenty of filter methods with names describing usecases)
Any other ideas are welcome
UseCase samples:
UseCase1 - Create report from "A"s:
- App should filter "A"s by filters read from user input + some other filters.
- Filtered "A"s should be mapped into given format and writen to file.
- File should be transfered to user.
UseCase2 - Export "A"s to external system:
- App should filter "A"s by filters read from user input + some other filters.
- Filtered "A"s should be mapped and be sent via SOAP to external system
- User should see a summary of the export.