Is .net standard library as a solution to bootstrap implementations and register them into Dependency Injection Container
.
PM > Install-Package Bootstrapper.Extensions.Microsoft.DependencyInjection
In order to use the package you need to have implementation of IBootstrapper
inside your project:
internal class TestBootstrapper : IBootstrapper
{
/// <inheritdoc/>
public IServiceCollection Initialize(IServiceCollection collection, IConfiguration configuration)
{
// ...
// Register Transient, Scoped, or Singleton implementations.
// ...
return services;
}
}
There are two options to bootstrap inside Program.cs:
- Automatic scanning for calling assembly:
using System.Reflection;
using Bootstrapper.Extensions.Microsoft.DependencyInjection;
//....
var builder = WebApplication.CreateBuilder(args);
//....
builder.Services.Bootstrap(builder.Configuration);
//....
- Using selective assemblies:
using System.Reflection;
using Bootstrapper.Extensions.Microsoft.DependencyInjection;
//....
var builder = WebApplication.CreateBuilder(args);
//....
builder.Services.Bootstrap(builder.Configuration, typeof(ClassA).Assemlby, typeof(ClassB).Assemlby);
//....