Domanda

i have a question related to read models in cqrs.

Assume we have two bounded contexts: A and B

In context A we build a readmodel based on the events from context A. We have some kind of dao to access the readmodel in A.

Now assume that B needs the same read model as A. As far as i understood, bounded context shouldn't depend on each other.

So how can i use the model from A. I see three possiblities to solve this

  1. Create an API Module for the read model in A and use this in context B (Would be a dependency between A and B)

  2. Create an seperate read model in context B thats exactly the same as in A (Would result in code duplication)

  3. Create a service facade (REST or SOAP or whatever) in B that is accessible from A to provide the read model (possibly the service doesnt provide exactly the data needed)

È stato utile?

Soluzione

Your read models don't belong to any bounded contexts, they are produced by some domain objects in some bounded context. But they are a separate component of your system.

Your bounded context shouldn't need any read model. Read model is an output of the domain, not the input. If you need 2 BC communicate, use events, not read models. Read models are for GUI/reporting, not for processing business rules.

Altri suggerimenti

It's actually very common to have dependencies between contexts, see relationships and context mapping in the DDD Reference.

In your example, context B depends on context A. Depending on the type of relationship (upstream-downstream, partnership, ...) context A decides how to let context B integrate with them (open-host, customer/supplier, ...).

Context A can provide a read model, events, or both. Integrating via events gives you independence, though integrating via a read model might be more practical for your example (but might cause friction once context A decides to diverge). Factors to take into account are your relationship with the other context, and the probability of change vs. cost of change.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top