I’ve created the infrastructure for a new project using DDD principles. I have repositories which feed factories/hydrators in the domain. An application layer acts as a facade, flaterning domain models to various view/edit Models when requested.
Edit models are mapped and merged back into the domain model, being validated by a serice using fluent validation. Any errors are logged and reported back to the user through an error service.
This all works perfectly. My concern now is how best to produce lists of these domain objects.
A few options come to mind:
1) Hydrate full domain models and then flatten these to a list. The domain models could be cached as an IEnumerable list. This collection is then flattened and pushed out to the requesting view.
2) Create a “projection” object which is lightweight representation of the domain model. This would require little to no hydrating, and could be pulled through the domain level and mapped to a viewModel and displayed.
3) “bypass” the domain and have a service called from the application layer which generates the IEnumerable. This would leave the domain clean.
I worry that solution 1 would be heavy for the sake of displaying a list of domain items. Whilst they will be cahched, due to the searchable nature of the domain, there is no guarentee the cache will do much good.
Any advice on what would be the best option would be appreciated.
I prefer the solution 2. Keeping the domain model clean is neccessary.
By CQS (Command Query Separated), we can implemente an effective and lightweight query architecuture.