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.

Custom Endpoint Initialization

Component:
NServiceBus
NuGet Package:
NServiceBus 10.x

Classes that implement NServiceBus.INeedInitialization are created and called as one of the first steps performed during endpoint creation. Use INeedInitialization to register custom endpoint configuration logic.

Instances are:

  • Located by assembly scanning.
  • Created as one of the first steps when the bus is created.
  • Created on the same thread that is creating the bus.
  • Created with Activator.CreateInstance(...) which means they:
    • Are not resolved from dependency injection (even if they are registered there).
    • Will not have any dependencies injected.
    • Must have a default constructor.

Once instantiated, Customize(...) 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 INeedInitialization are not handled by NServiceBus and will bubble up to the caller, creating the endpoint.

class NeedsInitialization :
    INeedInitialization
{
    public void Customize(EndpointConfiguration endpointConfiguration)
    {
        // Perform initialization
        // This is after Type Scanning.
        // Do NOT call the following here:
        // endpointConfiguration.AssemblyScanner();
    }
}