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
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With