How should I publish events not directly related to domain model

12 views
Skip to first unread message

James Bradt

unread,
Aug 11, 2010, 2:14:27 PM8/11/10
to ncqrs-dev
Good Day,

As part of the system that I am developing, I want the ability to
publish an event indicating that a command was processed by the domain
model.

The reason for this event is that I have a NSB saga that is above the
domain model (the saga actually sends the command to the domain). One
of the things that the saga can do is handle message timeouts (and
with the correct logic) - re-submittal of commands.

In the saga, I need to know that the command was processed so that I
can handle the saga timeout event correctly.

I know that I could have the saga subscribe to the domain events
(orderAdded, orderCancelled, orderAddFailed), but then the saga would
need to know every possible outcome of the domain, and I think that
over-complicates the saga.

So, (long story short), how would I obtain the ncqrs eventbus inside
the domain so I can publish the 'CommandProcessed' event?


Thanks,
James

James Bradt

unread,
Aug 11, 2010, 2:24:29 PM8/11/10
to ncqrs-dev
Not to get in the habit of answering my own questions but...

var eBus =
Ncqrs.NcqrsEnvironment.Get<Ncqrs.Eventing.ServiceModel.Bus.IEventBus>();
eBus.Publish(New MessageProcessed(commandId));

is what I came up with.

Thanks,
James

Szymon Pobiega

unread,
Aug 12, 2010, 1:36:45 AM8/12/10
to ncqr...@googlegroups.com
Hi James

I think it would be better to place this kind of code not inside the domain, but in ICommandServiceInterceptor. This way you can keep you domain free from instrastructure concerns (such as IEventBus).

Szymon

2010/8/11 James Bradt <james...@gmail.com>
Reply all
Reply to author
Forward
0 new messages