I have a multiple projects that are loading assemblies through unity IoC. There is an xml file that contains the configuration of the container like
<component
id="MyComponent"
service="MyNamespace.MyInterfaces.IMyComponent, MyNamespace.MyInterfaces"
type="MyNamespace.MyClasses.MyComponent, MyNamespace.MyClasses"
lifestyle="singleton">
<parameters>
<systemId>ID</systemId>
<!-- ctor -->
</parameters>
</component>
All of these projects have their own xml configuration file but share the same assemblies. What I would like to do is to place all the common assemblies in one folder (in the intranet) and let the unity container dynamically loads the assemblies from there. This for maintainability purpose: in this way when I have to update the assemblies I have all of them in one place only.
What I've tried so far:
- Googled until I got an headache
Intercept the
AssemblyResoveEvent
to manually load assemblies (as suggested in this answer) - with no luckprotected override void OnStartup(StartupEventArgs e) { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.AssemblyResolve += new ResolveEventHandler(LoadFromSameFolder); ... } static Assembly LoadFromSameFolder (object sender, ResolveEventArgs args) { string folderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string assemblyPath = Path.Combine(folderPath, "DLL\\", new AssemblyName(args.Name).Name + ".dll"); System.Diagnostics.Debug.WriteLine("ASS: " + assemblyPath); if (!File.Exists(assemblyPath)) return null; Assembly assembly = Assembly.LoadFrom(assemblyPath); return assembly; }
Struggled with
PrivateBinPath
property but there you can specify only sub-folders - not my case
Any suggestions? Is this even possible?