Question

Can NSB DTO be a command and an event at the same time?

I am hoping to use DefiningCommandAs() directive on the client side. However the same message will be considered an event on the server/handler side.

The idea is that I want to have 2 subsystems. Communication between the 2 will be done via Send() only.

  1. Is this a good pattern
  2. Should I create a special DTO construct instead to ferry messages across instead of reusing the event as a command dto.
Was it helpful?

Solution

Both Commands and Events derive from IMessage so it would technically be possible to Send() and Publish() the same message. However, this is not considered good design or practice and precisely the reason why the ICommands and IEvent interfaces were created, to stop people doing sending events and publishing commands. From a DDD perspective the two have very different meaning and purpose and should be treated as such. If you have chosen not to have a dependency on NServiceBus in your messages by implementing unobtrusive mode then bear this in mind and separate your events and commands into their respective assemblies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top