Conventions

Component: NServiceBus
NuGet Package NServiceBus (5.x)

A convention is a way of defining what a certain type is instead of using a marker interface or an attribute. Using conventions along with avoiding references to NServiceBus assemblies is referred to as unobtrusive mode. This is ideal for use in cross-platform environments.

Currently conventions exist to identify:

Messages can be defined in a Portable Class Library (PCL) and shared across multiple platforms even if the platform does not use NServiceBus for message processing.

var conventions = busConfiguration.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