Channel Scope
Every channel instance uses its own IServiceScope
. This means that if you add a scoped service to the DI container and use it in the channe's middleware, you'll have an unique instance per channel.
public class MyThing
{
public string Id { get; } = Guid.NewGuid().ToString( "N" );
}
// ...
IServiceCollection services = ; // ...
services.AddScoped<MyThing>();
// ...
public class MyAdapter : ChannelAdapter<IByteBuffer>, IInputChannelAdapter
{
private readonly string id;
public MyAdapter( MyThing thing )
{
id = thing.Id;
/*
For every new channel instance, a new MyThing instance will be created.
This instance will always be a singleton for the lifetime of each channel.
*/
}
public override Task ExecuteAsync( IAdapterContext context, IByteBuffer data )
{
// ...
}
}