Skip to content

Move endpoint installation to the HostApplicationBuilder level#7691

Closed
DavidBoike wants to merge 7 commits intomasterfrom
host-level-installation
Closed

Move endpoint installation to the HostApplicationBuilder level#7691
DavidBoike wants to merge 7 commits intomasterfrom
host-level-installation

Conversation

@DavidBoike
Copy link
Copy Markdown
Member

@DavidBoike DavidBoike commented Apr 8, 2026

Note

Instead of separate methods for registering endpoints vs. registering endpoint installers, instead this spike shows how installation could be a host-level concern, allowing usage like this:

var endpointConfiguration = new("EndpointName");
// configure endpoint

var builder = Host.CreateApplicationBuilder();
builder.Services.AddNServiceBusEndpoint(endpointConfiguration);

if (isInstall)
{
    await builder.InstallNServiceBusEndpoints();
}
else
{
    await builder.Build().Run();
}

InstallNServiceBusEndpoints() runs Create() on the endpoint, and then also forces installers to run, whether or not endpointConfiguration.EnableInstallers() was set, as the settings are finalized when the endpoints are added to the IServiceCollection. No user code or hosted services are run except what would need to be injected into NServiceBus component responsible for installing the endpoint.

The implementation calls builder.Build() and does not return the intermediate IHost so the builder cannot (by design) be used to also attempt to start the endpoints.

The result is much less need for testing that, for example, endpoints and installers aren't mixed, or registered as both endpoint and installer, etc.

Currently a little hacky, especially the extent to which forceRunInstallers is pushed through several levels, but I wanted to begin at a layer where the endpoint-specific keyed serviceProvider was already known.

@DavidBoike
Copy link
Copy Markdown
Member Author

@DavidBoike DavidBoike closed this Apr 16, 2026
@DavidBoike DavidBoike deleted the host-level-installation branch April 16, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant