.netnservicebusnservicebus3

Difference between IWantToRunAtStartup and IWantToRunWhenTheBusStarts in NServiceBus?


I'm creating an NServicebus hosted process and want to initialize my IOC container as well as create an instance of the Self-Hosted Web API. I'm trying to understand the conceptual differences between implementing the IWantToRunAtStartup and IWantToRunWhenTheBusStarts interfaces, so I can place my initialization code in the appropriate place. Which interface would be better to implement for these initializations?

I believe I would use IWantToRunAtStartup for the web api since it has the stop interface that will be needed when the process shuts down. But since the interface says it is Dependency injected should the IOC container be initialized in the IWantToRunWhenTheBusStarts or somewhere else?


Solution

  • In V3 use:

    IWantToRunWhenTheBusStarts 
    

    In V4 we have introduced a new interface called:

    IWantToRunWhenBusStartsAndStops
    

    This new interface is also used in v5.