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
Accessing the ISession
The way the NHibernate's ISession
object is accessed has changed. This object is no longer accessible through dependency injection or NHibernateStorageContext
. When Property or Constructor injection is used to get an instance of ISession
directly or through NHibernateStorageContext
, the code needs to be refactored after the upgrade to this version.
public class OrderHandler :
IHandleMessages<OrderMessage>
{
public Task Handle(OrderMessage message, IMessageHandlerContext context)
{
var nhibernateSession = context.SynchronizedStorageSession.Session();
nhibernateSession.Save(new Order());
return Task.CompletedTask;
}
}
As shown in the above snippet, the only way to access the ISession
object is through the Session()
extension method on IMessageHandlerContext.
.
The reason for removing the registration from dependency injection was to expose internal components of NServiceBus as little as possible and to have fewer behavioral changes in future versions. As such, the extension method called RegisterManagedSessionInTheContainer()
which used to enable this behavior is obsolete and can be removed.
Customizing the ISession Creation
It is no longer possible to customize the ISession
creation process. As such, the extension method call UseCustomSessionCreationMethod()
is no longer needed and should be removed.
Since most of the methods available on the ISessionFactory
are related to caching and with this existing NHibernate bug (see also accessing data), the benefit of having a customizable ISession
creation is debatable. To customize the created ISession
object, for example to apply a filter on the session level, the code must be moved to the handler and applied to the ISession
object on the Context.
Unique attribute no longer needed
NServiceBus will automatically make the correlated saga property unique without the need for an explicit [Unique]
attribute. This attribute can be safely removed from saga data types.
Refer to the NServiceBus upgrade guide for migrating from Version 5 to 6 to learn more about changes regarding sagas.