Adapter for the Microsoft.Extensions.DependencyInjection IoC container
Switch branches/tags
Nothing to show
Clone or download
Latest commit 6562bcd Sep 4, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
samples/AspNetCoreSample Moved sample project Sep 4, 2018
src Use better solution using child container Sep 4, 2018
tests Moved sample project Sep 4, 2018
.editorconfig Initial commit Aug 25, 2018
.gitignore Fix build Aug 25, 2018
LICENSE Initial commit Aug 25, 2018
NServiceBus.MSDependencyInjection.sln Moved sample project Sep 4, 2018
README.md Update build using sourcelink Aug 25, 2018
appveyor.yml Fix build Aug 25, 2018
build.cake Update build using sourcelink Aug 25, 2018
build.ps1 Initial commit Aug 25, 2018
build.sh Initial commit Aug 25, 2018

README.md

NServiceBus.MSDependencyInjection

Build status NuGet Version License

Support for the Microsoft.Extensions.DependencyInjection container.

Usage

public IServiceProvider ConfigureServices(IServiceCollection services)
{
    // register any services to IServiceCollection
    // ...

    var endpointConfiguration = new EndpointConfiguration("Sample.Core");
    endpointConfiguration.UseTransport<LearningTransport>();
    endpointConfiguration.UseContainer<ServicesBuilder>(customizations =>
        {
            customizations.ExistingServices(services);
        });

    endpoint = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();
}

If you need to register the IEndpointInstance also to the service collection please use following pattern:

public IServiceProvider ConfigureServices(IServiceCollection services)
{
    ...
    IEndpointInstance endpointInstance = null;

    services.AddSingleton<IMessageSession>(sp => endpointInstance);

    endpointConfiguration.UseContainer<ServicesBuilder>(c => c.ExistingServices(services));

    endpointInstance = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();
}