Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

NServiceBus.MSDependencyInjection

Build status NuGet Version License

Support for the Microsoft.Extensions.DependencyInjection container.

Usage

public void 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();
}

To share the used service provide across (ASP) .NET Core and NServiceBus (recommended) you need to return the created service provider.

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

    var endpointConfiguration = new EndpointConfiguration("Sample.Core");
    endpointConfiguration.UseTransport<LearningTransport>();

    UpdateableServiceProvider container = null;
    endpointConfiguration.UseContainer<ServicesBuilder>(customizations =>
        {
            customizations.ExistingServices(services);
            customizations.ServiceProviderFactory(sc => 
            {
                container = new UpdateableServiceProvider(sc);
                return container;
            });
        });

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

    return container;
}

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();
}

About

Adapter for the Microsoft.Extensions.DependencyInjection IoC container

Topics

Resources

License

Packages

No packages published