Windsor Castle - InstallerFactory Case Study

Does anyone have an example code for using the Castle InstallerFactory windsor to order installers?

It does not seem to be found in documents or elsewhere.

Greetings

+4
source share
1 answer

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

When using FromAssembly, you should not rely on the order in which your installers will be created or installed. It is non-deterministic, which means you never know what it will be. If you need to install the installers in a specific order, use InstallerFactory.

In addition to this, you must inherit from the InstallerFactory class and apply your own rules regarding the instantiation of certain types of installer.

All of the above methods have an overload that accepts an InstallerFactory instance. Most of the time you will not care about this, and everything will work. However, if you need to have tighter control over the installers from the assembly (the order of influence in which they are installed, change the way they are created or install only some, but not all) that you can inherit from this class and provide your own implementation goals.

A sample class might 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 container initialization code:

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

Hope this helps!

+8
source

Source: https://habr.com/ru/post/1393478/


All Articles