This is part of the NServiceBus Upgrade Guide from Version 5 to 6, which also includes the following individual upgrade guides for specific components:
Feature Details
- Assembly Scanning Changes in NServiceBus Version 6
- No Async Suffix
- Dependency Injection Changes in NServiceBus Version 6
- Deprecated TransportMessage in NServiceBus Version 6
- Endpoint API changes in NServiceBus Version 6
- Extension Seam Changes in NServiceBus Version 6
- Migrate handlers and sagas to Version 6
- Header API changes in NServiceBus Version 6
- Messaging Changes in NServiceBus Version 6
- Moving away from IBus in Version 6
- Recoverability Changes in Version 6
- Serialization Changes in NServiceBus Version 6
- Subscription Changes in NServiceBus Version 6
- Transaction Configuration Changes in NServiceBus Version 6
Transports
- Azure Service Bus Transport (Legacy) Upgrade Version 6 to 7
- RabbitMQ Transport Upgrade Version 3 to 4
- SQL Server Transport Upgrade Version 2 to 3
- SQL Server Transport Upgrade - Supporting Unicode in Headers
Persistence
- Upgrade from NServiceBus Azure Version 6
- NHibernate Persistence Upgrade Version 6 to 7
- NHibernate Persistence - Resolving incorrect timeout table indexes
- RavenDB Persistence Upgrade from 3 to 4
Hosting
Other
- Moving to the DataBus AzureBlobStorage Package
- Azure Cloud Services Host Upgrade Version 6 to 7
- NServiceBus.Azure package deprecated
- Gateway Upgrade Version 1 to 2
- NServiceBus Testing Upgrade Version 5 to 6
- Callback Changes in NServiceBus Version 6
- Migrating the distributor to use sender-side distribution
- Tool and Helper Changes in NServiceBus Version 6
Configure type removed
In NServiceBus version 5, the Configure
type is used to provide runtime access to the local endpoint address, scanned types, etc, via dependency injection. In version 6, these values are accessed as follows:
Immutable
The default container used internally is immutable once the endpoint is started.
Settings
Settings can be accessed via the FeatureConfigurationContext
, see Features for more details. Runtime access via dependency injection is provided by taking a dependency on the ReadOnlySettings
type.
Builder
This is no longer supported in NServiceBus version 6. Instead of using IBuilder
directly, use a specific dependency injection library.
Scanned types
Access to types found during assembly scanning is provided via Settings.
.
Local address
Access to the endpoint address is provided via Settings.
.
Encryption service
It is no longer possible to access the builder to create an encryption service. If dependency injection access is required, use it directly in the factory delegate in the RegisterEncryptionService
method.
Conventions
Conventions are no longer injected. Conventions must be retrieved with Settings.
over ReadOnlySettings
.
Dependency injection
Explicitly setting property values via .
and .
is deprecated in NServiceBus version 6. Instead configure the properties explicitly using:
endpointConfiguration.RegisterComponents(
registration: components =>
{
components.ConfigureComponent(
componentFactory: builder =>
{
return new MyHandler
{
MyIntProperty = 25,
MyStringProperty = "Some string"
};
},
dependencyLifecycle: DependencyLifecycle.InstancePerUnitOfWork);
});
IConfigureComponents no longer registered
To access IConfigureComponents
at runtime, create a new feature and put the following code in the .
method
var container = context.Container;
container.ConfigureComponent(
componentFactory: builder => new MyDependency(container),
dependencyLifecycle: DependencyLifecycle.InstancePerCall);
Instances passed to the configuration API are no longer disposed
var builder = new ContainerBuilder();
builder.RegisterInstance(new MyService());
var container = builder.Build();
endpointConfiguration.UseContainer<AutofacBuilder>(
customizations: customizations =>
{
customizations.ExistingLifetimeScope(container);
});
While the above example shows how an existing DI instance can be passed into the configuration API using Autofac, the same behavior can be applied to all of the currently supported dependency injection. Previous versions of DI treated the externally passed-in DI instance as if it were owned by the DI adapter and disposed the DI when the bus was disposed. This behavior changed in NServiceBus version 6. When a DI customization is passed in (as in the above example), then the DI instance is no longer disposed. It is the responsibility of the DI owner to dispose the DI instance.
endpointConfiguration.UseContainer<AutofacBuilder>();
The above example shows how a new DI instance can be assigned using the configuration API. While the DI instance used in this example is Autofac, the same behavior can be applied to all of the currently supported dependency injection. When passing a new DI instance, the endpoint owns that instance and will also be responsible for disposing it when endpoint stopped.