z4kn4fein / stashbox-extensions-dependencyinjection

Stashbox Integration for ASP.NET Core, .NET Generic Host and ServiceCollection based applications.
https://z4kn4fein.github.io/stashbox
MIT License
17 stars 2 forks source link

Support GenericHost #2

Closed onizet closed 6 years ago

onizet commented 6 years ago

Hello,

I'm using a netapp for background services, and use the new (generic host)[https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-2.1].

/// <summary>
/// Extensions of the <see cref="IHostBuilder"/> for adding <see cref="IStashboxContainer"/>.
/// </summary>
public static class GenericHostBuilderExtensions
{
     /// <summary>
     /// Sets the default service provider to <see cref="IStashboxContainer"/>.
     /// </summary>
     /// <param name="builder">The <see cref="IHostBuilder"/> instance.</param>
     /// <param name="configure">The callback action which can be used to configure the internal <see cref="IStashboxContainer"/>.</param>
     /// <returns>The modified <see cref="IHostBuilder"/> instance.</returns>
     public static IHostBuilder UseStashbox(this IHostBuilder builder, System.Action<IStashboxContainer> configure = null) =>
        builder.UseServiceProviderFactory<IStashboxContainer>(new StashboxServiceProviderFactory(configure));

     /// <summary>
     /// Sets the default service provider to <see cref="IStashboxContainer"/>.
     /// </summary>
     /// <param name="builder">The <see cref="IHostBuilder"/> instance.</param>
     /// <param name="container">An already configured <see cref="IStashboxContainer"/> instance to use.</param>
     /// <returns>The modified <see cref="IHostBuilder"/> instance.</returns>
     public static IHostBuilder UseStashbox(this IHostBuilder builder, IStashboxContainer container) =>
         builder.UseServiceProviderFactory<IStashboxContainer>(new StashboxServiceProviderFactory(container));
}
z4kn4fein commented 6 years ago

Hi @onizet

Thanks for sharing this, i published a new package which contains this integration: https://www.nuget.org/packages/Stashbox.Extensions.Hosting/

Please feel free to tell me if you have any more suggestions about it, thanks!

onizet commented 6 years ago

This is very cool, thank you :)