gpt4 book ai didi

caSTLe-windsor - CaSTLe Windsor - 使用 InstallerFactory 的示例

转载 作者:行者123 更新时间:2023-12-04 23:28:13 31 4
gpt4 key购买 nike

有没有人有一些使用城堡 Windsor InstallerFactory 来订购安装程序的示例代码?

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

干杯

最佳答案

您只能使用 InstallerFactoryFromAssembly 一起使用类(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.



除此之外,您应该继承 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
}
}

这是容器初始化的代码:
IWindsorContainer container = new WindsorContainer().Install(FromAssembly.This(new CustomInstallerFactory()));

希望这可以帮助!

关于caSTLe-windsor - CaSTLe Windsor - 使用 InstallerFactory 的示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9043421/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com