Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Baubit.DI.Extensions

CircleCI codecov
NuGet NuGet
.NET Standard 2.0 License: MIT
Known Vulnerabilities

Extensions for Baubit.DI.

Installation

dotnet add package Baubit.DI.Extensions

Usage

Adding Modules Directly to IServiceCollection

// Using configuration action with fluent chaining
var provider = new ServiceCollection()
    .AddModule<MyModule, MyConfiguration>(
        cfg => cfg.ConnectionString = "Server=localhost",
        cfg => new MyModule(cfg))
    .AddSingleton<ILogger, ConsoleLogger>()
    .BuildServiceProvider();

// Using configuration builder action
var provider = new ServiceCollection()
    .AddModule<MyModule, MyConfiguration>(
        builder => builder.WithRawJsonStrings("{\"ConnectionString\": \"Server=localhost\"}"),
        cfg => new MyModule(cfg))
    .BuildServiceProvider();

Building Service Provider from ComponentBuilder

var result = ComponentBuilder.CreateNew()
    .WithModule<MyModule, MyConfiguration>(
        cfg => cfg.ConnectionString = "Server=localhost",
        cfg => new MyModule(cfg))
    .BuildServiceProvider();

if (result.IsSuccess)
{
    IServiceProvider serviceProvider = result.Value;
}

API Reference

Method Description
AddModule<TModule, TConfiguration>(this IServiceCollection, Action<TConfiguration>, Func<TConfiguration, TModule>) Adds a module to the service collection using configuration action and module factory
AddModule<TModule, TConfiguration>(this IServiceCollection, Action<ConfigurationBuilder<TConfiguration>>, Func<TConfiguration, TModule>) Adds a module to the service collection using configuration builder action and module factory
BuildServiceProvider(this IComponent, IServiceCollection?) Builds a service provider from a component
BuildServiceProvider(this Result<IComponent>, IServiceCollection?) Builds a service provider from a component result
BuildServiceProvider(this Result<ComponentBuilder>, IServiceCollection?) Builds component and creates a service provider

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages