Reputation: 419
I have been looking for an example of this and I'm unsure of how this is done here, since grains are isolated.
Example: Say I have a User grain, which can reference X Order grains and each order grain has a collection of OrderItem grains associated with them. What is the preferred method of accessing all of these items?
The only way I have thought of is having a collection of PK's for each of the Order grains inside the User grain, and OrderItems within the Order grain, then call them as you would any grain.
Sorry if this is a little novice of a question, but I haven't been able to find a good example solution to review.
Upvotes: 2
Views: 629
Reputation: 2583
Sounds like you are partitioning way too narrow. Is there an actual reason why each order item (and perhaps even the order) is its own grain type? If it's just a data holder without any non-trivial logic, nor is referenced externally, I would just keep that data inside the Order itself, as it doesn't seem like each item should have its own identity. If we map concepts to DDD terminology, each aggregate typically correlates to a grain type, and you wouldn't typically make each order item behave as an aggregate root. So you just reference an Order grain that happens to contain all of its order items inside it. That's basically just a generalization without knowing much about your actual domain. It IS possible in a few domains to treat order items as their own aggregate root, but make sure that's what you want, because the complexity of having them in isolation is not trivial (ie: what happens if the Order grain dies but not the order items, etc).
Upvotes: 4