Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I be using the streamId in the EventStore?

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?

like image 320
CodingHero Avatar asked Feb 01 '12 08:02

CodingHero


1 Answers

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);
    }
}
like image 78
Mikael Östberg Avatar answered Jan 01 '23 11:01

Mikael Östberg