Skip to content

Helper functions for registering decorators of keyed services that support Autofac indexes (Autofac.Features.Indexed.IIndex<K,V>)

License

Notifications You must be signed in to change notification settings

paolov/Autofac.KeyedDecorators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Autofac.KeyedDecorators

Plugin for Autofac enabling decoration of multiple keyed services (Autofac.Features.Indexed.IIndex<K,V>)

var builder = new ContainerBuilder();

//simple registration per service and per decorator
 builder.RegisterKeyedType<FirstService>()
        .WithDecorator<FirstDecorator>()
        .WithDecorator<SecondDecorator>()
        .ForInterface<IService>()
        .WithKey("A");

builder.RegisterKeyedType<SecondService>()
       .WithDecorator<FirstDecorator>()
       .WithDecorator<SecondDecorator>()
       .ForInterface<IService>()
       .WithKey("B");

//or multiple registrations
var mapping = new Dictionary<string, Type>()
{
    ["A"] = typeof(FirstService),
    ["B"] = typeof(SecondService),
};

var decorators = new[]
{
    typeof(FirstDecorator),
    typeof(SecondDecorator)
};

builder.RegisterKeyedTypes(mapping)
       .ForInterface<IService>()
       .WithDecorators(decorators);

var container = builder.Build();

var factory = container.Resolve<IIndex<string, IService>>();
var svc = factory["A"];

 svc.Execute();

About

Helper functions for registering decorators of keyed services that support Autofac indexes (Autofac.Features.Indexed.IIndex<K,V>)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages