Should I put this Invariant within a domain service or aggregate itself?
"Marco Paul [email protected] [domaindrivendesign]" <[email protected]> Mon, 18 May 2015 14:30:51 -0400
| Newsgroups | gmane.comp.programming.domain-driven-design |
|---|---|
| Message-ID | <CAMRntEjg2URwj3PBMY6gHxRcqBTymvKM5TrKYDxop_mF9bOxtA@mail.gmail.com> |
I'm working on a side project to learn and apply DDD within the "Daily Deal' domain. In my purchasing context, i have an invariant where a user can only purchase 'x' amount of deals per deal. so it seems wasteful for my deal aggregate to load all purchases from all users just to check and see how many times (if any) the user has purchased this deal. I see two ways i could go about this. 1. Put this logic within a domain service which would allow a pre-condition to already have been met when the Purchase method on the Deal aggregate is invoked. 2. My repository implementation could always populate the purchases collection of the deal for the purchasing user. hmm...not sure about this one. any guidance would be great!