简体   繁体   English

Castle Windsor - 使用InstallerFactory的示例

[英]Castle Windsor - Example of using InstallerFactory

Does anyone have some sample code of using a castle windsor InstallerFactory for ordering the installation of Installers? 有没有人有一些示例代码使用城堡windsor InstallerFactory来订购安装程序的安装?

Can't seem to find it in the docs or elsewhere. 似乎无法在文档或其他地方找到它。

Cheers 干杯

You can only use the InstallerFactory in conjunction with the FromAssembly class. 您只能将InstallerFactoryFromAssembly类一起使用。

When using FromAssembly you should not rely on the order in which your installers will be instantiated/installed. 使用FromAssembly时,不应该依赖安装程序实例化/安装的顺序。 It is non-deterministic which means you never know what it's going to be. 这是非确定性的,这意味着你永远不知道它会是什么。 If you need to install the installers in some specific order, use InstallerFactory. 如果需要按特定顺序安装安装程序,请使用InstallerFactory。

In addition to that you should inherit from the InstallerFactory class and apply your own rules regarding the instantiation of particular installer types. 除此之外,您应该从InstallerFactory类继承并应用有关特定安装程序类型实例化的自己的规则。

All of the above methods have an overload that takes an InstallerFactory instance. 所有上述方法都有一个带有InstallerFactory实例的重载。 Most of the time you won't care about it and things will just work. 大多数时候你不会关心它,事情就会奏效。 However if you need to have tighter control over installers from the assembly (influence order in which they are installed, change how they're instantiated or install just some, not all of them) you can inherit from this class and provide your own implementation to accomplish these goals. 但是,如果您需要对程序集中的安装程序进行更严格的控制(影响它们的安装顺序,更改它们的实例化方式或只安装一些,而不是全部安装),您可以从此类继承并提供自己的实现实现这些目标。

Sample class could look like this: 示例类可能如下所示:

public class CustomInstallerFactory : InstallerFactory
{
    public override IEnumerable<Type> Select(IEnumerable<Type> installerTypes)
    {
        return installerTypes.Reverse(); // just as an example
    }
}

And here is the code for the container initialization: 这是容器初始化的代码:

IWindsorContainer container = new WindsorContainer().Install(FromAssembly.This(new CustomInstallerFactory()));

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM