When Configuration Ends

Component: NServiceBus
NuGet NServiceBus (5.x)
This interface is deprecated in Version 6 and has been replaced with Features.

Classes that implement IWantToRunWhenConfigurationIsComplete are executed when configuration is completed, right before the bus is created. Use IWantToRunWhenConfigurationIsComplete for any tasks that need to be run at the end of bus creation life-cycle. This might include logging diagnostic information about configuration or initialization logic that downstream components depend on.

Instances are:

  • Located by assembly scanning and automatically registered into the configured container during bus creation. These are registered as Instance Per Call.
  • Created as the last step before the bus is created.
  • Created on the same thread that is creating the bus.
  • Created by the Container which means they:
  • Will have dependencies injected.
  • Do not require a default constructor.
Instances of IWantToRunWhenConfigurationIsComplete are registered in the Container after instances of INeedInitialization are created and run.

Once created Run(...) is called on each instance. These calls are made sequentially on the thread that is creating the bus. The order of these calls is determined by the order in which the configured container returns instances.

Exceptions thrown by instances of IWantToRunWhenConfigurationIsComplete are not handled by NServiceBus. These will bubble up to the creator of the bus.

class RunWhenConfigurationIsComplete :
    IWantToRunWhenConfigurationIsComplete
{
    public void Run(Configure configure)
    {
        // initialization logic
    }
}

Samples


Last modified