-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Control over view_id when creating a view #94
Comments
The Note that the
Absolutely, but this is a case where you would want a custom query to handle this logic. The |
Thanks for your answer, but I think the main issue is that both the For the use aggregate1::Aggregate1Event;
use aggregate2::Aggregate2Event;
enum QueryEvents {
Aggregate1Event(Aggregate1Event),
Aggregate2Event(Aggregate2Event),
}
impl DomainEvent for QueryEvent {
fn event_type(self) -> String {
match self {
QueryEvent::Aggregate1Event(event) => event.event_type(),
QueryEvent::Aggregate2Event(event) => event.event_type(),
}
}
}
impl From<Aggregate1Event> for QueryEvents {
fn from(event: Aggregate1Event) -> Self {
QueryEvent::Aggregate1Event(event)
}
}
impl From<Aggregate2Event> for QueryEvents {
fn from(event: Aggregate2Event) -> Self {
QueryEvent::Aggregate2Event(event)
}
} For the CQRS framework I would add a new abstraction called |
I see your point now. With two aggregates you certainly need two different Query implementations even though it they have the same backing storage and view projection. It would certainly make sense to reduce some of this overhead. I also like the idea of a bounded context tying multiple aggregates together, that has been a point of confusion. @carlos-verdes would you mind opening a new issue with your thoughts on these changes? |
Related with #90
When we use CQRS the main idea is to segregate commands and queries right?
On this crate we have control over the aggregate_id when we are managing commands, however when we build a view the view_id is populated always with the aggregate_id of an specific aggregate.
This second part for me breaks the main advantage of CQRS, first of all I should be able to use events from 2 different aggregates and secondly (as the problem on issue #90) in many cases the query result (let's call it view record) will not match 1:1 with an aggregate nor have the same id.
You can see in the picture how the Query and Command model are not 1:1 (and they should not)
Example where aggregate id is different from view id:
The Portfolio aggregate commands will use a generated id for identity and will add the user_id as part of the metadata.
The view will use user_id as a key, and in every PortfolioCreated event will decide if it updates the view or not.
Example with different aggregates:
This case can be managed if we consider PortfolioUsdValue as an aggregate, but the reality is just a view (we will never execute a command from users).
We need to be able on this scenario to receive events from Portfolio and Market aggregates.
What I found
When we submit a command we are able to provide 3 parameters:
However when we write a query we can only update the payload of the view record.
When I see the implementation of
execute_with_metadata
I see why the aggregate_id becomes the view_id (this is only a specific case but not the general expected behavior of a query entity)Then I see the trait Query has couple of things I'm not fully aligned:
dispatch
functionCurrent implementation:
Proposal
So maybe we could change this into something like:
And to not disrupt current implementation we can provide
From
implementations like:Share your thoughts I may be missing something.
The text was updated successfully, but these errors were encountered: