SaguiItay

My blog has moved!

You should be automatically redirected in 4 seconds. If not, visit:
http://itaysagui.wordpress.com
and update your bookmarks.

Saturday, September 10, 2011

Windsor: Loading installers from the execution folder

When using Windsor, it is necessary to load the various IWindowsInstallers into the container. One standard way of doing this is using a code similar to the below:
container.Install(FromAssembly.InDirectory(new AssemblyFilter(".")));
The above code will load all the installed that are located in the execution folder.

However, in certain cases, when your code is running in different contexts, such as under IIS, you need to be a bit more explicit about things. You need to tell Windsor to load assemblies from the folder where you are running, and not from some run-time "copy" or cache folder.

For that, you can use the following class:

public class ExecutingAssemblyFilter : AssemblyFilter
{
    public ExecutingAssemblyFilter()
        : base(new FileInfo(new Uri(Assembly.GetExecutingAssembly).CodeBase).LocalPath).Directory.ToString())
    { }
 }

This class inherits from AssemblyFilter, and automatically provides the correct path. It should be used like this:
container.Install(FromAssembly.InDirectory(new ExecutingAssemblyFilter()));

Labels: ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home