Side-by-side with legacy Azure Service Bus

Component: Azure Service Bus Transport
NuGet Package NServiceBus.Transport.AzureServiceBus (1-pre)
Target NServiceBus Version: 7.x
This page targets a pre-release version and is subject to change prior to the final release.

If it's necessary to run an endpoint instance using the Azure Service Bus transport and an endpoint instance using the legacy Azure Service Bus transport in the same process and AppDomain, there is the risk of name collision between classes coming from the two transports.

To avoid name clashes, use aliases to reference types of one of the transports. For example, to define an alias for the legacy Azure Service Bus transport, add the following snippet to the project file:

<Target Name="ChangeAliasesOfNugetRefs" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
  <ItemGroup>
    <ReferencePath Condition="'%(FileName)' == 'NServiceBus.Azure.Transports.WindowsAzureServiceBus'">
      <Aliases>LegacyASB</Aliases>
    </ReferencePath>
  </ItemGroup>
</Target>

Once the alias is defined, reference the alias in the C# source files where it is needed by adding it to the usings list:

extern alias LegacyASB;

The alias can now be used to reference types from the Azure Service Bus transport assembly:

var legacyASB = configurationASB.UseTransport<LegacyASB::NServiceBus.AzureServiceBusTransport>();

Related Articles


Last modified