Autofac自动注入Named的依赖项

注入三个接口:

builder.RegisterType().Named("one").As();
builder.RegisterType().Named("two").As();
builder.RegisterType().Named("three").As();

注入引用:

builder.Register>(c =>
    {
        var cc = c.Resolve();
        return named => cc.Resolve(named);
    });

解决方案很精妙啊~

来自stackoverflow:http://stackoverflow.com/questions/2888621/autofacs-funct-to-resolve-named-service

转载于:https://my.oschina.net/wower/blog/282006

你可能感兴趣的:(Autofac自动注入Named的依赖项)