Skip to content
ASP.NET Core integration for Stashbox (https://github.com/z4kn4fein/stashbox)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
sample
src
test
.gitignore
.travis.yml
LICENSE
README.md
appveyor.yml
patch-version.ps1 Fix patcher script Jun 10, 2019
sn.snk
stashbox.extensions.dependencyinjection.sln

README.md

stashbox-extensions-dependencyinjection

Appveyor build status Travis CI build status Tests

Package Version
Stashbox.Extensions.Dependencyinjection NuGet Version
Stashbox.AspNetCore.Hosting NuGet Version
Stashbox.Extensions.Hosting NuGet Version

This package is an integration for the Microsoft.Extensions.DependencyInjection framework and contains extensions for the IWebHostBuilder and the IHostBuilder interfaces.

Stashbox.Extensions.Dependencyinjection

Contains an IServiceProvider implementation which can be used to set Stashbox as the default service provider of the framework. Also contains extension methods (UseStashbox(...)) defined on the IServiceCollection interface, whichs result you can use as the return value of the ConfigureServices(IServiceCollection services) method of your Startup class.

You have the option to add your services into the IServiceCollection and use Stashbox at the end of your configuration section:

public IServiceProvider ConfigureServices(IServiceCollection services)
{
    services.AddScoped<IService1, Service1>();
        
    return services.UseStashbox();
}

Or you can configure your services directly through Stashbox:

public IServiceProvider ConfigureServices(IServiceCollection services)
{
    return services.UseStashbox(container =>
    {
        container.RegisterScoped<IService1, Service1>();
        container.Configure(config => config.WithOptionalAndDefaultValueInjection());
    });
}

Controllers

If you want to let the runtime activate your controllers through Stashbox, you can register them into the service collection:

public class Startup
{
    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        services.AddMvc().AddControllersAsServices();
    }
}

Stashbox.AspNetCore.Hosting

Adds the UseStashbox(...) extension method to the IWebHostBuilder.

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseStashbox()
            .Build();
}

With this type of integration the ASP.NET Core runtime will optionally look for a ConfigureContainer(IStashboxContainer container) method on the Startup class to configure the given container.

public class Startup
{
    public void ConfigureContainer(IStashboxContainer container)
    {
        container.RegisterScoped<IService1, Service1>();
        container.Configure(config => config.WithOptionalAndDefaultValueInjection());
    }
}

Stashbox.Extension.Hosting

Adds the UseStashbox(...) extension method to the IHostBuilder which integrates Stashbox easily with your .NET Generic Host.

using (var host = new HostBuilder()
    .UseStashbox()
    .ConfigureContainer<IStashboxContainer>((context, container) =>
    {
        container.Register<Foo>();
    })
    .ConfigureServices((context, services) =>
    {
        services.AddHostedService<Service>();
    })
    .Build())
{
    // start and use your host
}
You can’t perform that action at this time.