I have a design idea for a large project at work and I think I have it figured out but would really love to get some feedback on a) the idea in general, and b) my proposed implementation.
The basic idea is simple: I want to create an ASP MVC application that can be extended in the future with additional controllers and views without having to recompile the code. The idea is to have one MVC application with a very basic set of features and then extend the functionality by adding another 'Application.dll" that contains controllers, data, and business logic that are specific to that application. The views will simply be copied into the same directory as the main MVC application during install.
The problem is that MVC does its routing on types within the same assembly so even if I move the routing definitions to the database, the MvcHttpHandler would not be able to route anything to the new Dll since it doesn't "know" the controller types in it. Looking at the MVC code, I found that to load the controllers they are simply calling Activator.CreateInstance which looks only in the current assembly.
My solution is simple but maybe I'm missing something: I will override the MvcHttpHandler by either replacing the ControllerFactory directly (not sure how to do that) or by duplicating that functionality in a derived class. The new code will read the request and try to load the controller first from the current assembly and then from the extended ones. Once the proper assembly is found, I will use CreateInstance and pass that assembly to it to get the controller I want.
See Question&Answers more detail:os