Thanks to @twenzel NServiceBus.MSDependencyInjection
0.1.4 is now available on nuget: NuGet Gallery | NServiceBus.MSDependencyInjection 0.1.4
The PR I raised had been merged and it’s now possible to configure an ASP.Net Core project like in the following snippet:
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddSignalR();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
IEndpointInstance endpointInstance = null;
services.AddSingleton<IMessageSession>(_ => endpointInstance);
var ec = new EndpointConfiguration("some-endpoint-name");
ec.UseTransport<ATransport>();
UpdateableServiceProvider container = null;
ec.UseContainer<ServicesBuilder>(c =>
{
c.ExistingServices(services);
c.ServiceProviderFactory(sc =>
{
container = new UpdateableServiceProvider(sc);
return container;
});
});
endpointInstance = Endpoint.Start(ec).GetAwaiter().GetResult();
return container;
}
Using the above approach the result is that the ASP.Net Core application and the NServiceBus endpoint will effectively share the same container, making sure both can resolve and share the same components.