温莎城堡 - 使用 InstallerFactory 的示例

发布于 2024-12-29 08:28:31 字数 88 浏览 2 评论 0原文

有谁有一些使用温莎城堡 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.

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怀里藏娇 2025-01-05 08:28:31

您只能将 InstallerFactoryFromAssembly 类结合使用。

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

除此之外,您应该从 InstallerFactory 类继承,并应用您自己的关于特定安装程序类型的实例化的规则。

以上所有方法都有一个采用 InstallerFactory 实例的重载。大多数时候你不会关心它,一切都会正常进行。但是,如果您需要对程序集中的安装程序进行更严格的控制(影响它们的安装顺序、更改它们的实例化方式或仅安装其中一些,而不是全部),您可以从此类继承并提供您自己的实现实现这些目标。

示例类可能如下所示:

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

这是容器初始化的代码:

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

希望这会有所帮助!

You can only use the InstallerFactory in conjunction with the FromAssembly class.

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.

In addition to that you should inherit from the InstallerFactory class and apply your own rules regarding the instantiation of particular installer types.

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.

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文