I am just playing with Microsoft Unity 2 now, and need to know whether it’s possible to configure a container so it loads up the assemblies from the file system, rather than having to configure it to load from config file (which contains all the mappings to the right assemblies) or register the type objects programatically. I need this to essentially load plugins. All plugins have implemented the same contract interface. What I want to achieve is that I can drop a new assembly (plugin) in the main app folder and that is automatically discovered by Unity. is that possible or I need to use MEF for that?
any help is very much appreciated, thank you very much.
Unity does not support that behavior out-of-the-box. But it is not difficult to implement it.
A FileSystemWatcher can notify your application whenever you drop a new assembly in your plugin folder. Then it is just a matter of conventions, what you do with that new file. Use Assembly.Load to load you DLL. Then you can scan it for implementations of your interface
assembly.GetExportedTypes().Where(t => typeof(IMyInterface).IsAssignableFrom(t))and then you need to register your implementations with the container.
As this service is part of your infrastructure I think its OK to reference your container there which I would rather avoid otherwise.