1

问题:

类构造函数如下:

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){}
}

问题:

代码注册方法:

  1. ParsingRulesProvider与规则 A 和 B?
  2. ParsingRulesProvider与所有实现IParsingRule 的对象?
  3. ARuleBRule
4

1 回答 1

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"));
于 2012-12-04T13:21:57.650 回答