I need to write an extensible ASP.NET MVC 3 application, and the extension is a .dll for a very specific purpose (i.e.: forum extension, blog extension, wiki extension, etc.).
The extension would not have any views, although this should make this process much easier. It should have only controllers and several models .
I thought about implementing this with MVC scopes and loaded them like this:
// Global.asax public static void PreApplicationStartMethod() { foreach (var file in Directory.GetFiles( Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Extensions/"), "*.dll")) { BuildManager.AddReferencedAssembly(Assembly.LoadFile(file)); } } protected void Application_Start() { AreaRegistration.RegisterAllAreas(); ... }
Now it worked fine, but still, it seems like a pretty old and static way .... NET 4 has a Managed Extensibility Framework. MVC 3 has dependency injection.
I read about portable areas and SharpArchitecture. I tried to understand the scope of the Orchard plugin both from the source code and from the documentation. But still I'm not sure what I should use.
To make my question more practical - how do you incorporate controllers and models from an external project into the main MVC web application? What is the best way to do this? Should I use dependency injection here?
Thanks.
source share