Installation 在Castle Windsor中注册运行时依赖项

Installation 在Castle Windsor中注册运行时依赖项,installation,castle-windsor,ioc-container,Installation,Castle Windsor,Ioc Container,在我正在重构的代码中,我有以下情况: void Plugin(IExternalService service) { var facade = new Facade( new ExternalServiceWrapper(service), new Dependency1(), new Dependency2()); } 其中Dependency1和Dependency2是IDependency1和IDependency2的实现 如何将其

在我正在重构的代码中,我有以下情况:

void Plugin(IExternalService service)
{
    var facade = new Facade(
        new ExternalServiceWrapper(service),
        new Dependency1(),
        new Dependency2());
}
其中
Dependency1
Dependency2
IDependency1
IDependency2
的实现

如何将其转换为Windsor安装程序中的注册?我似乎不知道如何将
IExternalService
的实例传递给容器


编辑我无法控制插件的创建。我想将其用作组合根以连接所有依赖项。

要注册现有实例,可以使用实例方法:

container.Register(Component.For<IExternalService>().Instance(service));
container.Register(Component.For().Instance(service));

要注册现有实例,可以使用实例方法:

container.Register(Component.For<IExternalService>().Instance(service));
container.Register(Component.For().Instance(service));

不清楚您想要实现什么目标。您希望容器调用Plugin方法,还是希望从Plugin方法中调用容器?我正在尝试获取
Facade
(使用Windsor实现
IFacade
解析。插件的入口点必须是我的合成根,它发生在运行时的某个时候,我无法控制它。因此,实际上您不会调用
新外观
,而是调用
容器.Resolve()
?是的!除非有其他方法,否则这几乎是正确的。我只是不知道如何流利地进行此注册。不清楚您试图完成什么。您希望容器调用插件方法,还是希望从插件方法中调用容器?我正试图拥有
外观的所有依赖项
(实现用Windsor解析的
IFacade
。插件的入口点必须是我的合成根目录,它发生在运行时的某个时候,我无法控制它。因此,实际上您不会调用
新外观
,而是调用
容器.Resolve()
?是的!除非有其他方法,否则这是正确的。我只是不知道如何流利地进行注册。最后,这就是我所需要的。容器自行处理。我只需要在安装程序中按正确的顺序指定它。最后,这就是我所需要的。容器自行处理。我只需要指定在安装程序中按正确的顺序安装。