I'm using Castle Windsor to register a number of interfaces each of which can created with a generic factory method. i.e.
container.Register(Component.For(typeof(IFirstService))
.UsingFactoryMethod(k => GetService<IFirstService>())
.LifeStyle.Singleton);
container.Register(Component.For(typeof(ISecondService))
.UsingFactoryMethod(k => GetService<ISecondService>())
.LifeStyle.Singleton);
Rather than add registration code for each interface, can I use the Types
method to register them all in one go (all interfaces derive from IService
) eg:
container.Register(Types
.FromThisAssembly()
.Where(t => typeof(IService).IsAssignableFrom(t))
.Configure(c => c.UsingFactoryMethod(k => GetService<?>()));