NServiceBus 10.2 introduces built-in support for hosting endpoints in .NET Generic Host applications via IServiceCollection.. This makes the NServiceBus. package's UseNServiceBus extension methods unnecessary.
NServiceBus version 10.2 or later is required.
UseNServiceBus is deprecated
The UseNServiceBus extension methods on HostApplicationBuilder and IHostBuilder have been deprecated. Replace calls to UseNServiceBus with AddNServiceBusEndpoint on the host's service collection, then remove the NServiceBus. package reference.
HostApplicationBuilder
Replace:
var builder = Host.CreateApplicationBuilder();
builder.UseNServiceBus(endpointConfiguration);
var host = builder.Build();
with:
var builder = Host.CreateApplicationBuilder();
builder.Services.AddNServiceBusEndpoint(endpointConfiguration);
var host = builder.Build();
IHostBuilder
Replace:
var host = Host.CreateDefaultBuilder()
.UseNServiceBus(context =>
{
var endpointConfiguration = new EndpointConfiguration("MyEndpoint");
return endpointConfiguration;
})
.Build();
with:
var builder = Host.CreateApplicationBuilder();
var endpointConfiguration = new EndpointConfiguration("MyEndpoint");
builder.Services.AddNServiceBusEndpoint(endpointConfiguration);
var host = builder.Build();
Remove the package
After replacing UseNServiceBus with AddNServiceBusEndpoint, remove the NServiceBus. package reference from the project. The AddNServiceBusEndpoint method is provided by the core NServiceBus package starting with version 10.2.