How should I be using the streamId in the EventStore?
Asked Answered
A

1

5

In J Oliver's EventStore how should i be using the streamId when opening a stream?

Should I have a new stream/streamid for each object/aggregate root object?

So should my order state objects which i think should be ar objects each have a streamid?

Auschwitz answered 1/2, 2012 at 8:50 Comment(0)
A
7

The StreamId is your Aggregate Root Id. You probably want to include it in your Commands. Since they are Guids, you can set them before you send the command from the client which means that you can act upon the same AR without having to load it from the read model.

Here is an example using the CommonDomain project:

class CreateOrder {
    public Guid OrderId;
    ... 
}

class CreateOrderHandler {
    void Handle(command) {
        var order = Order.Create(command.OrderId);
        // This is using the Id property from AggregateBase in CommonDomain
        repository.Save(order, Guid.NewGuid(), null);
    }
}
Archaeological answered 1/2, 2012 at 9:33 Comment(2)
But should I have a Aggregate Root Id for each order object? So the system would have many, many Aggregate RootsAuschwitz
If you have identified Order as an Aggregate root, each instance of Order should have its own Id. I don't know about your system, but Order probably is an AR. Think about how you would do in a relational system. Then you would have a unique Id for each Order and this is the same concept. The Aggregate Root Id is the unique Id for an instance of an Order.Shipentine

© 2022 - 2024 — McMap. All rights reserved.