问题
Problem:
Class constructor is as below:
public class ParsingRulesProvider : IParsingRulesProvider{
public ParsingRulesProvider(List<IParsingRule> rules){}
}
We have two rules:
public class ARule : IParsingRule{
public ARule(IASomeObject someObject){}
}
public class BRule : IParsingRule{
public BRule(IBSomeObject someObject){}
}
Questions:
How to register in code:
ParsingRulesProvider
with rule A and B?ParsingRulesProvider
with all objects implementing IParsingRule?ARule
andBRule
?
回答1:
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"));
来源:https://stackoverflow.com/questions/13700177/windsor-castle-resolving-multiple-dependencies-with-same-interface