Skip to content

A tiny library for having Channel<T> as a Dependency Injection resource in a sane manner

License

Notifications You must be signed in to change notification settings

frankhaugen/Frank.Channels.DependencyInjection

Repository files navigation

Frank.Channels.DependencyInjection

A tiny library for having Channel<T> as a Dependency Injection resource in a sane manner


GitHub License NuGet NuGet

GitHub contributors GitHub Release Date - Published_At GitHub last commit GitHub commit activity GitHub pull requests GitHub issues GitHub closed issues


Usage

using Frank.Channels.DependencyInjection;

// Register the channel of a type as a dependency:
services.AddChannel<string>();

// Use the channel as a dependency in various ways:
var channel = provider.GetRequiredService<Channel<string>>();
var channelWriter = provider.GetRequiredService<ChannelWriter<string>>();
var channelReader = provider.GetRequiredService<ChannelReader<string>>();

Advanced usage

using Frank.Channels.DependencyInjection;

// Register the channel of a type as a dependency with a custom configuration:
services.AddChannel<string>(options =>
{
    options.BoundedCapacity = 100;
    options.FullMode = BoundedChannelFullMode.Wait;
    options.SingleReader = true;
    options.SingleWriter = true;
});

// Use the channel as a dependency in various ways:
var channel = provider.GetRequiredService<Channel<string>>();
var channelWriter = provider.GetRequiredService<ChannelWriter<string>>();
var channelReader = provider.GetRequiredService<ChannelReader<string>>();

About

A tiny library for having Channel<T> as a Dependency Injection resource in a sane manner

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages