EventSourceId

7 views
Skip to first unread message

Ross

unread,
Aug 29, 2010, 9:50:37 AM8/29/10
to ncqrs-dev
Hi,

I just got the latest drop of ncqrs and I cannot figure out how to set
the aggregate root Id, it seems to be auto assigned. Is there a way I
can set the Id?

Thanks

Ross

unread,
Aug 29, 2010, 9:56:31 AM8/29/10
to ncqrs-dev
Aaargg, never mind. It would seem I can do this in the proper place,
the proper place being the constructor.

Pieter Joost van de Sande

unread,
Aug 29, 2010, 10:25:52 AM8/29/10
to ncqr...@googlegroups.com
The set of the EventSourceId property is protected. You can set it only when the Version is 0, in other words, when there are no events applied yet.

Pieter Joost van de Sande

unread,
Aug 29, 2010, 10:28:35 AM8/29/10
to ncqr...@googlegroups.com
You should not initialize the id in the ctor. This should be done in the event handler, an example can be found here: http://github.com/ncqrs/ncqrs/blob/master/Samples/MyNotes/src/Domain/Note.cs

Hope that helps.

PJ

On Sun, Aug 29, 2010 at 3:56 PM, Ross <rossja...@gmail.com> wrote:

seagile

unread,
Aug 29, 2010, 12:10:02 PM8/29/10
to ncqrs-dev
From a design perspective, I'd advice against doing identifier
management within "state" handlers.

On 29 aug, 16:28, Pieter Joost van de Sande <p...@born2code.net>
wrote:
> You should not initialize the id in the ctor. This should be done in the
> event handler, an example can be found here:http://github.com/ncqrs/ncqrs/blob/master/Samples/MyNotes/src/Domain/...

Pieter Joost van de Sande

unread,
Aug 30, 2010, 12:07:02 AM8/30/10
to ncqrs-dev
Good point. We added changed the responsibility some time ago. Forgot about that. So no need to initialize the EventSourceId yourself in an eventhandler. Just set it in the ctor and you are fine.

SteveG

unread,
Sep 11, 2010, 11:58:00 AM9/11/10
to ncqrs-dev
I had to comment out the following in the Note class:

//EventSourceId = noteId;

the EventSourceId has a Guid at this point, and the noteId is empty
guid, so it was setting it back to empty if this isn't commented
out...



On Aug 30, 12:07 am, Pieter Joost van de Sande <p...@born2code.net>
wrote:
> Good point. We added changed the responsibility some time ago. Forgot about
> that. So no need to initialize the EventSourceId yourself in an
> eventhandler. Just set it in the ctor and you are fine.
>
> I updated the MyNotes sample according to this:http://github.com/ncqrs/ncqrs/blob/development/Samples/MyNotes/src/Do...

Pieter Joost van de Sande

unread,
Sep 11, 2010, 3:39:11 PM9/11/10
to ncqrs-dev
Hey Steve,

On Sat, Sep 11, 2010 at 5:58 PM, SteveG <steven....@gmail.com> wrote:
I had to comment out the following in the Note class:

//EventSourceId = noteId;

the EventSourceId has a Guid at this point, and the noteId is empty
guid, so it was setting it back to empty if this isn't commented
out...

Thanks for reporting this. It is seems to be a bug in the sample app that sneaked into there after we changed the id initialization a short time go.

The code in the sample app was assuming that the client generates the ID, but the client wasn't doing that, so the ID remained empty.


Cheers,

PJ


Martin Aatmaa

unread,
Sep 11, 2010, 4:01:30 PM9/11/10
to ncqrs-dev
Hi Yves,

Is there a particular reason you recommend this?

Both the other sample apps out there do identity management in the
event handlers:

1) Greg Young's SimpleCQRS sample:

http://github.com/gregoryyoung/m-r/blob/master/SimpleCQRS/Domain.cs

Line 10
private void Apply(InventoryItemCreated e)


2) Mark Nijhof's Fohjin.DDD.Example:

http://github.com/martinaatmaa/Fohjin/blob/master/Fohjin.DDD.Example/Fohjin.DDD.Domain/Account/ActiveAccount.cs

Line 216
private void onAccountCreated(AccountOpenedEvent accountOpenedEvent)


I have no idea which is better, so I'd love to hear your input on
this.

Thanks,
Reply all
Reply to author
Forward
0 new messages