I\'m trying to upgrade a solution from NServiceBus 5 to 6. Currently, we are injecting IBus to a service class so that the service can send messages to the bus as needed. Now
Use an IWantToRunWhenEndpointStartsAndStops
implementation to inject the IMessageSession
for your service class after the bus has started.
Here is the relevant section from the Upgrade Guide for NServiceBus.Host: https://docs.particular.net/nservicebus/upgrades/host-6to7#iwanttorunwhenendpointstartsandstops-interface-in-version-7-of-nservicebus-host
An alternative would be to switch to the NServiceBus Windows Service Bootstrap instead of using NServiceBus.Host where you will have more control over the endpoint's lifecycle.