tags:

views:

220

answers:

2

Has anyone found a smart way to use NServiceBus, without having to implements that useless IMessage marker interface for all messages?

Especially, when using DomainEvents, I would absolutely hate to couple my domains to a specific servce bus implementation.

A: 

The IMessage interface is needed so that NServiceBus can automatically register those types in the serializer. When using domain events, it isn't recommended to publish them directly on the bus - instead, a domain event handler would translate them to service-level events (which inherit IMessage).

Udi Dahan
Hey Udi, thanks for the quick reply!Of course it is a marker interface - but having to repeat domain messages to service messages adds quite a bit of cruft - 95% of the time they would be 1:1. I would definitely want to to avoid that, typing isn't my best skill.It would be great if there was some kind of pluggable convention module that would tell the bus how to recognize a valid message (MEF, name space, class suffix, my own interface...).I am thinking of using some of those weavers like PostSharp, but I would hate it to add just another level of complexity to this solution.
Jan Limpens
You could use something like AutoMapper.
Udi Dahan
I like that idea. If there only was MI...
Jan Limpens
A: 

You might be able to create your own interfaces implementing the NSB marker interface and then ILMerge the NSB dependencies into your own DLL. This should allow you to only require references to your own Dll and no external references to NSB.

Its what NSB does for its own dependencies so you should be able to extend the idea, be sure to check out the pitfalls of this approach though - Udi blogged about it recently

http://www.udidahan.com/2010/08/01/cautiously-merging-il/

Shahid