Generic plugin loader with MEF
Since The Monack Framework will be extendable with modules, I have been looking for an easy way to load assemblies and implement their interfaces. For this I found the Managed Extensibility Framework, also called MEF.
MEF is an open source library that is included in .net 4.0 and higher or can be downloaded here.
The documentation is quite clear, especially if you do the simple calculator example. But the example is still quite extensive if you want to load a lot of different interfaces, so I made a generic class to load interfaces:
public class Loader<T>
private List<T> _available;
public IEnumerable<T> LoadedItems
public Loader(string path)
private void Load(string path)
var container = new CompositionContainer(new AssemblyCatalog(path));
With this class you can easily load interfaces of an assembly:
List<IAuthorization> authorizations = new List<IAuthorization>();
Loader<IAuthorization> loader = new Loader<IAuthorization>(@"D:\code\MonackFr\MonackFr.Mvc\bin\UserManagement.dll");
Of course you still need to set the export annotation in the classes that implement IAuthorization:
public class UserController : IAuthorization