NServiceBus: DRY with unobtrusive conventions

Many times when working with NServiceBus in unobtrusive mode you may feel that you are repeating the same conventions over and over again on all the endpoints.

The IWantToRunBeforeConfiguration interface is a great help in order to embrace the DRY principle.

Just define your implementation in an assembly referenced by all the endpoints:

1
2
3
4
5
6
7
8
9
10
11
12
13
public class UnobtrusiveConventions : IWantToRunBeforeConfiguration
{
public void Init()
{
Configure.Instance
.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"));
}
}

and NServiceBus will pick this class automatically for each endpoint.

Share Comments