Contents
|
Support for running NServiceBus in Unobtrusive modeWhen using NServiceBus you define your message contracts using plain C# classes or interfaces. So far so good. In order for NServiceBus to find those classes when scanning your assemblies you need to mark them with the special IMessage interface.
This dependency can cause problems if you have different services that run different versions of NServiceBus. I’m not going into the details since Jonathan Oliver has a great write up on this very subject. This is not a big deal for commands because they are always used with in the boundary of a single service and it’s fair to require a service to use the same version of NServiceBus. But when it comes to events this becomes more of a problem since requiring all of your services to use the same version of NServiceBus and there by forcing them to upgrade NServiceBus all at once is not an ideal thing. The solutionThere are a couple of ways you can solve this. NServiceBus V3.0.0 has a few changes that will help you further.
Unobtrusive modeThis new feature in NServiceBus V3.0.0 allows you to pass in your own conventions to determine which types are message definitions instead of using the IMessage interface. Below is a snippet that shows how to define those conventions: Configure.With() .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.EndsWith("Commands")) .DefiningEventsAs(t => t.Namespace != null && t.Namespace.EndsWith("Events")) .DefiningMessagesAs(t => t.Namespace != null && t.Namespace.EndsWith("Messages")) .DefiningEncryptedPropertiesAs(p => p.Name.StartsWith("Encrypted")); The code above tells NServiceBus to treat all interfaces/classes with a namespace that ends with “Messages” as messages. As you see you can also specify conventions for the new ICommand and IEvent feature as well. NServiceBus supports property level encryption by using a special WireEncryptedString property and the last line in the snippet is the unobtrusive way to accomplish that encryption. That is pretty much all there is to it. A working sample can be found here. This article was written by Andreas Öhlund and the original blog post can be found here. |