AI agents: use the documentation index at llms.txt to locate machine-readable pages. This section is indexed by https://docs.particular.net/nservicebus/llms.txt. The markdown version of this page is served as plain text. An MCP server at /mcp serves the same content via the search_docs and read_doc tools; it is read-only and needs no credentials. Markdown versions of documentation pages are available by appending .md to the page URL. Directory URLs use index.md. They are served as text/plain because some retrieval backends reject text/markdown.

Before Configuration Finalized

Component:
NServiceBus
NuGet Package:
NServiceBus 9.x

During endpoint creation the configuration object used to construct the endpoint becomes frozen and locked. Classes that implement IWantToRunBeforeConfigurationIsFinalized are instantiated and called just before this happens. Use IWantToRunBeforeConfigurationIsFinalized for any last minute alterations to the configuration that may rely on other configuration settings.

Instances are:

  • Located by assembly scanning.
  • Created just before the configuration is frozen.
  • Created on the same thread that is creating the bus.
  • Created with Activator.CreateInstance(...) which means they:
    • Are not resolved by dependency injection (even if they are registered there).
    • Will not have any dependencies injected.
    • Must have a default constructor.

Once instantiated, Run(...) is called on each instance. These calls are made on the same thread that is creating the endpoint. The order in which instances are instantiated and run is non-deterministic and should not be relied upon.

Exceptions thrown by instances of IWantToRunBeforeConfigurationIsFinalized are unhandled by NServiceBus and will bubble up to the caller.

class RunBeforeConfigurationIsFinalized :
    IWantToRunBeforeConfigurationIsFinalized
{
    public void Run(SettingsHolder settings)
    {
        // update config instance
        settings.Set("key", "value");
        // after this config.Settings will be frozen
    }
}