1

我正在自动注册多个实现相同接口的组件:

container.Kernel.Resolver.AddSubResolver(
    new ArrayResolver(container.Kernel));

container.Register(AllTypes.FromAssembly(Assembly.GetExecutingAssembly())
    .BasedOn<IPaymentPostProcessor>()
    .WithService.FromInterface(typeof(IPaymentPostProcessor))
    .Configure(c => c.Named(c.Implementation.Name))
    .Configure(c => c.LifeStyle.PerWebRequest));

当我依赖数组本身时,这有效:

public class PaymentPostProcessorManager{
    public PaymentPostProcessorManager(IPaymentPostProcessor[] processors){}
}

但如果我依赖于实现接口的特定组件,则不会:

public class SpecialService{
    public OtherService(SpecificPostProcessor processor){}
}

这失败了,它说没有为SpecificPostProcessor注册任何组件。如果我单独注册该SpecificPostProcessor,则数组分辨率最终会包含它两次。

如何根据接口进行自动注册并让它自动注册特定的依赖项?

4

1 回答 1

3

如果要将其公开为服务,则WithService.Self()需要添加。SpecificPostProcessor

于 2012-06-30T06:04:53.743 回答