serverlesstechnology / cqrs

A lightweight, opinionated CQRS and event sourcing framework.
Other
382 stars 40 forks source link

Defining multiple aggregates in `ApplicationState` #87

Closed daniel-mader closed 10 months ago

daniel-mader commented 10 months ago

The cqrs-demo shows how the aggregate BankAccount is used in the ApplicationState:

pub struct ApplicationState {
    pub cqrs: Arc<PostgresCqrs<BankAccount>>,
    pub account_query: Arc<PostgresViewRepository<BankAccountView, BankAccount>>,
}

The CqrsFramework<A, ES> can only hold one single Aggregate, so I assume I need to add all my aggregates as additional fields to the ApplicationState?

pub struct ApplicationState {
    pub bank_account: Arc<PostgresCqrs<BankAccount>>,
    pub bank_account_query: Arc<PostgresViewRepository<BankAccountView, BankAccount>>,
    pub other_aggregate: Arc<PostgresCqrs<OtherAggregate>>,
    pub other_aggregate_query: Arc<PostgresViewRepository<OtherAggregateView, OtherAggregate>>,
}

Is this the intended way of doing it?

Thanks in advance!

davegarred commented 10 months ago

That's correct, @daniel-mader. Each aggregate should have it's own PostgresCqrs framework.

That being said two frameworks may share one or more queries. E.g., if you had a BankAccount and a Customer aggregate, you might have several queries that need information from both of them.