温莎城堡-使用InstallerFactory的示例 [英] Castle Windsor - Example of using InstallerFactory

查看:74
本文介绍了温莎城堡-使用InstallerFactory的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人使用示例城堡温莎InstallerFactory命令安装安装程序吗?

Does anyone have some sample code of using a castle windsor InstallerFactory for ordering the installation of Installers?

似乎无法在文档或其他地方找到它。

Can't seem to find it in the docs or elsewhere.

欢呼声

推荐答案

您只能使用 InstallerFactory FromAssembly 类结合。


使用FromAssembly时,您不应依赖于实例化/安装安装程序的顺序。这是不确定的,这意味着您永远都不知道会是什么样。如果需要按特定顺序安装安装程序,请使用InstallerFactory。

When using FromAssembly you should not rely on the order in which your installers will be instantiated/installed. 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. 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.

示例类如下:

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()));

希望这会有所帮助!

这篇关于温莎城堡-使用InstallerFactory的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆