Let\'s say I have a library Lib.dll, which uses Castle.Windsor to initialize its services.
I have a main application App.exe, which loads Lib.dll on runtime using re
You probably will consider loading the plugin in a separate AppDomain, with a different private path, look at AppDomainSetup. Of course there is a drawback that you neeed a separate app domain for your plugin, but sometimes this is considered a good practice.
You can try to load the unresolved assemblies within your code by AssemblyResolve event
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
string typeToLoad = args.Name;
string myPath = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;
return Assembly.LoadFile(...); //or return Assembly.GetExecutingAssembly() etc.
};
You probably can't do it in easy and elegant way if App.exe doesn't provide you Castle Windsor's container instance to configure your services.
If it is not exposed directly, maybe you can access it using Service Locator? Or find it on your own using reflection on App.exe assembly?
The best solution will be if code in App.exe calls specific method in your library (i.e. it can look for particular interface implementation, like IModuleInitializer
or something, create an instance of it and call some kind of Initialize
method passing container instance to your code).
You could also think about extensibility frameworks like MEF, but that can be a bit overkill and make big influence on App.exe.