We are using unity as IoC. We came across unique problem. We have created interface called IPlugin. This interface is shared across various third party vendors to develop th
You could write a bit of Reflection code that scans a folder for add-in assemblies and registers all IPlugin
implementations with the container.
Something like this ought to work:
var assemblies = // read all assemblies from disk
var pluginTypes = from a in assemblies
from t in a.GetExportedTypes()
where typeof(IPlugin).IsAssignableFrom(t)
select t;
foreach (var t in pluginTypes)
container.RegisterType(typeof(IPlugin), t);
(code may not compile)
var assemblies = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "Worker*.dll").Select(f => Assembly.LoadFile(f)).ToArray<Assembly>();
(from asm in assemblies
from t in asm.GetExportedTypes()
where typeof(ICommonWorker).IsAssignableFrom(t) && t.IsClass
select t).ForEach(x =>
{
unityContainer.RegisterType(typeof(ICommonWorker), x, x.FullName, new ContainerControlledLifetimeManager());
});
If anyone still cares, this is what I did to load DLL's dynamically which implemented a specific interface (ICommonWorker).