Conventions

Component: NServiceBus | Nuget: NServiceBus (Version: 6.x)

A convention is a way of defining what a certain type is instead of using a marker interface or an attribute.

Currently conventions exist to identify:

When Conventions are combined with avoiding an reference to any NServiceBus assemblies this is referred to as Unobtrusive Mode. This makes it also ideal to use in cross platform environments. Messages can be defined in a Portable Class Library (PCL) and shared across multiple platform even though not all platforms use NServiceBus for message processing.

Edit
var conventions = endpointConfiguration.Conventions();
conventions.DefiningCommandsAs(
    type =>
    {
        return type.Namespace == "MyNamespace.Messages.Commands";
    });
conventions.DefiningEventsAs(
    type =>
    {
        return type.Namespace == "MyNamespace.Messages.Events";
    });
conventions.DefiningMessagesAs(
    type =>
    {
        return type.Namespace == "MyNamespace.Messages";
    });
conventions.DefiningDataBusPropertiesAs(
    property =>
    {
        return property.Name.EndsWith("DataBus");
    });
conventions.DefiningExpressMessagesAs(
    type =>
    {
        return type.Name.EndsWith("Express");
    });
conventions.DefiningTimeToBeReceivedAs(
    type =>
    {
        if (type.Name.EndsWith("Expires"))
        {
            return TimeSpan.FromSeconds(30);
        }
        return TimeSpan.MaxValue;
    });

Related Articles


Last modified