title: MEF with MVC 4 or 5 - Pluggable Architecture (2014)
body: <p>I am trying to build a MVC4/MVC5 application with a pluggable architecture like Orchard CMS. So I have a MVC application which will be the startup project and take care of auth, navigation etc. Then there will be multiple modules built separately as asp.net class libraries or stripped down mvc projects and have controllers, views, data repos etc.</p>
  
  <p>I have spent all day going through tutorials on the web and downloading samples etc and found that Kenny has the best example around - <a href="http://kennytordeur.blogspot.in/2012/08/mef-in-aspnet-mvc-4-and-webapi.html" rel="noreferrer">http://kennytordeur.blogspot.in/2012/08/mef-in-aspnet-mvc-4-and-webapi.html</a></p>
  
  <p>I am able to import the controllers from the modules(separate DLLs) if I add reference to those DLLs. But the reason behind using MEF is being able to add modules at runtime. I want the DLLs along with views to be copied to a ~/Modules// directory in the startup project (I have managed to do this) and MEF would just pick them up. Struggling to make MEF load these libraries.</p>
  
  <p>There is also MefContrib as explained in this answer <a href="https://stackoverflow.com/questions/17579232/asp-net-mvc-4-0-controllers-and-mef-how-to-bring-these-two-together">ASP.NET MVC 4.0 Controllers and MEF, how to bring these two together?</a> which is the next thing I am about to try. But I'm surprised that MEF doesnt work out of the box with MVC. </p>
  
  <p>Has anyone got a similar architecture working (with or without MefContrib)? Initially I even thought of stripping Orchard CMS and using it as a framework but it is too complex. Also would be nice to develop the app in MVC5 to take advantage of WebAPI2.</p>