Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
346 views
Welcome To Ask or Share your Answers For Others

1 Answer

The end of this article shows how to implement your own ControllerFactory. Basically, you derive from DefaultControllerFactory and then wire it up in Application_Start() in your global.asax.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...