问题:
类构造函数如下:
public class ParsingRulesProvider : IParsingRulesProvider{
public ParsingRulesProvider(List<IParsingRule> rules){}
}
我们有两条规则:
public class ARule : IParsingRule{
public ARule(IASomeObject someObject){}
}
public class BRule : IParsingRule{
public BRule(IBSomeObject someObject){}
}
问题:
如何在代码中注册:
ParsingRulesProvider
有规则A和B吗?ParsingRulesProvider
所有对象实现了IParsingRule?ARule
和BRule
?答案 0 :(得分:0)
AD1)
container.Kernel.Resolver.AddSubResolver(new ListResolver(container.Kernel, true));
AD2)
container.Register(Component
.For<IParsingRulesProvider>()
.ImplementedBy<ParsingRulesProvider>());
AD3)
container.Register(Component
.For<IParsingRule>()
.ImplementedBy<ARule>()
.LifeStyle.Singleton
.Named("ARule"));
container.Register(Component
.For<IParsingRule>()
.ImplementedBy<BRule>()
.LifeStyle.Singleton
.Named("BRule"));