Dependency injection 温莎城堡多种服务注册
我已经研究了Castle Windsor文档和stackoverflow abut dependencies resolution中使用此容器的现有主题,但我仍然不知道这是否可能(如果可能,那么如何实现): 1) 要注册接口的多个实现,例如:Dependency injection 温莎城堡多种服务注册,dependency-injection,castle-windsor,Dependency Injection,Castle Windsor,我已经研究了Castle Windsor文档和stackoverflow abut dependencies resolution中使用此容器的现有主题,但我仍然不知道这是否可能(如果可能,那么如何实现): 1) 要注册接口的多个实现,例如: container.Register(Component.For<IWait<IWebDriver>>().UsingFactoryMethod(ctx => SmallWait));
container.Register(Component.For<IWait<IWebDriver>>().UsingFactoryMethod(ctx => SmallWait));
container.Register(Component.For<IWait<IWebDriver>>().UsingFactoryMethod(ctx => MediumWait));
container.Register(Component.For<IWait<IWebDriver>>().UsingFactoryMethod(ctx => LongWait));
container.Register(Component.For().UsingFactoryMethod(ctx=>SmallWait));
Register(Component.For().UsingFactoryMethod(ctx=>MediumWait));
Register(Component.For().UsingFactoryMethod(ctx=>LongWait));
`
只需通过ResolveAll
来解析它,或者在IEnumerable
的构造函数参数或字段中自动接收它
2) 要从容器中删除组件的注册
.Named()
为他们提供唯一的ID