I'm stumbling trying to find a proper way to model this scenario: I have 3 different aggregates within same Bounded Context:
- A Student
- A University
A University of Interest
public class Student : Entity, IAggregateRoot { public string Name { get; } public string StateAbbreviaiton { get; } ... } public class University : Entity, IAggregateRoot { public string Name { get; } public string StateAbbreviaiton { get; } ... } public class UniveristyOfInterest : Entity, IAggregateRoot { public Guid StudentId { get; } public Guid UniversityId { get; } public ResidencyType ResidencyType { get; } ... }
A UniveristyOfInterest is an entity that happens when a student selects a University they are interested in attending. UniveristyOfInterest is an Entity because it will ultimately contain a lot more information about the experience the user could have with the University including financial data, ROI calculations, etc. Each UniveristyOfInterest for a Student will be saved in some repository.
UniveristyOfInterest has an Enumeration called ResidencyType. ResidencyType has 3 possible values: InState, OutState, and Unknown. The business rule is if StateAbbreviation value of Student is same as StateAbbreviation value of University, then ResidencyType is InState, otherwise OutState (assuming we have valid values for both Student and University).
The UniversityOfInterest aggregate must contain the business rules for determining ResidencyType. All of the research I've done recommends Aggregates only know of other aggregates based on the aggregates Id value (no references to foreign aggregates). My UniversityOfInterest constructor is passed StudentId and UniversityId. How do I reach back and get their respective StateAbbreviation values so I can properly administer the business rule for determining ResidencyType inside the UniversityOfInterest aggregate?
I thought about also passing stateAbbreviation for both Student and University in constructor of UniversityOfInterest, but that seems klunky.
Any suggestions on how to properly administer business rule determining ResidencyType requiring data from foreign aggregates within the same Bounded Context?
UniveristyOfInterest
would also cache a reference to aUniversity
andStudent
if they were already loaded. Alternately there is aRepository
object somewhere that can be asked to retrieve them given that you have the Guids. If your doing this across a network the Service could send the correlated objects to reduce round tripping.