Damian
Damian

Reputation: 2789

NEventStore get projection which lists all aggregates of a given type

I am using the IRepository interface from the NEventStore.Domain project. I would like to create a projection that is a list of all the aggregates of the given aggregate type. How would I go about doing this:

So if I have a ReportBatch aggregate, I am looking to list all the report batches I have saved. How can I accomplish this? Am I barking up the wrong tree with projections? Should I just be saving to a ReportBatchList aggregate when I get Created events for the ReportBatch.

Upvotes: 0

Views: 496

Answers (1)

Phil Sandler
Phil Sandler

Reputation: 28046

Should I just be saving to a ReportBatchList aggregate when I get Created events for the ReportBatch.

No. You should have a projection that writes to a read model each time it receives a Created event. You would then query this read model to get the list. The read model could be a database (SQL or NoSQL), an in-memory construct, a text file, etc.

Note that it will not be "a list of all the aggregates of the given aggregate type". It's a read model, and while a read model may have knowledge of data that is generated by an aggregate, it does not directly represent an aggregate.

Event Sourcing is an advanced form of Command Query Responsibility Segregation (CQRS), in which writes (aggregates et al) and reads (projections and read models) are conceptually completely separate.

Upvotes: 2

Related Questions