0

If I have an instance of an aggregate, and that aggregate has, for example, different related contacts, then I should be asking the aggregate who its contacts are. Pretty standard. That pattern can be genericized to an ancestor so that different types of aggregates can provide different types of contacts. I just ask an instance of an aggregate to give me its instances of its contacts. (The entire list of contact types are not known at compile-time.)

However! If all aggregates have contacts of some type, but different aggregates have different types of contacts, how should I go about asking each type of aggregate what types of contacts they have?

Specifics: In my application, I have aggregates such as "loan", "property", and others. A "loan" has certain system-defined contacts, such as "primary lender" and "originator". A "property" has its own system-defined contacts, such as "owner" and "property manager". To throw a kink in it, we allow our customers to define their own types of contacts for each type of aggregate. This is why I have to actually query for the types of contacts instead of hard-coding anything.

I would ideally like to preset the user with a drop-down list of aggregate types ("loan", "property") and when they select an object type, they would be presented with a second drop-down list of the types of contacts for that aggregate. So if they choose "property", they see a list of "owner" and "property manager". But if they choose "loan", the second list shows "primary lender" and "originator".

My first thought is that querying metadata should be done through a static method on the class. That would be fine, except that I'd have a big switch/case statement to figure out which aggregate was chosen so that I can query the correct class.

switch (chosenAggregate) {
   case typeLoan:
      var contacts = LoanType.GetContactTypes();
   case typeProperty:
      var contacts = PropertyType.GetContactTypes();
}

I'm specifically working in C# / .NET Framework 4.7.2, but my question is more about design and architecture.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.