Conventions

Component: NServiceBus
NuGet Package NServiceBus (3.x)
Standard support for version 3.x of NServiceBus has expired. For more information see our Support Policy.

A convention is a way of defining what a certain type is instead of using an 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.

// NOTE: When self hosting, '.DefiningXXXAs()' has to be before '.UnicastBus()',
// otherwise it will result in:
// 'InvalidOperationException: "No destination specified for message(s): MessageTypeName"
configure.DefiningCommandsAs(
    type =>
    {
        return type.Namespace == "MyNamespace.Messages.Commands";
    });
configure.DefiningEventsAs(
    type =>
    {
        return type.Namespace == "MyNamespace.Messages.Events";
    });
configure.DefiningMessagesAs(
    type =>
    {
        return type.Namespace == "MyNamespace.Messages";
    });
configure.DefiningDataBusPropertiesAs(
    property =>
    {
        return property.Name.EndsWith("DataBus");
    });
configure.DefiningExpressMessagesAs(
    type =>
    {
        return type.Name.EndsWith("Express");
    });
configure.DefiningTimeToBeReceivedAs(
    type =>
    {
        if (type.Name.EndsWith("Expires"))
        {
            return TimeSpan.FromSeconds(30);
        }
        return TimeSpan.MaxValue;
    });

Related Articles


Last modified