I’m automatically registering multiple components that implement the same interface:
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));
This works when I have a dependency on the array itself:
public class PaymentPostProcessorManager{
public PaymentPostProcessorManager(IPaymentPostProcessor[] processors){}
}
But doesn’t if I have a dependency on a specific component implementing the interface:
public class SpecialService{
public OtherService(SpecificPostProcessor processor){}
}
This fails, it says no components have been registered for SpecificPostProcessor. If I individually register that SpecificPostProcessor, it the array resolution ends up including it twice.
How can I do the automatic registration based on the interface AND have it automatically register it for specific dependencies?
You need to add
WithService.Self()for yourSpecificPostProcessorIf you want to expose it as a service.