问题描述
在我的Asp.Net MVC 4的WebAPI应用程序,我想在以后的时间,这是在单独的程序集(的的WebAPI初始化之后)动态加载其他WebApiControllers。此外,我想添加路由在运行时的控制器。
in my Asp.Net MVC 4 WebApi application I want to load additional WebApiControllers dynamically at a later time (after the WebApi initialization), which are in separate assemblies. Furthermore I want to add routes for those controllers at runtime.
我想,如果这是可以做到的。
I am wonder, if this is possible to do.
我的目标是建立一个web应用程序,在那里我可以上传控制器(编译的程序集)和控制器将这个应用程序内自动托管。
My goal is to build a web-app, where I can upload controllers (compiled assemblies) and the controllers will be automatically hosted within this application.
我已经尝试过通过实现我自己的AssemblyResolver类来实现这一点,但(据我所看到的),则AssemblyResolver在初始化阶段加载一次。
I've already tried to achieve that by implementing my own AssemblyResolver class, but (as far as I have seen), the AssemblyResolver is loaded once at initialization phase.
可能有一个选项重新加载所有控制器。
May be there is an option to "re-load" all controllers.
任何帮助将AP preciated!
Any help will be appreciated!
马吕斯
推荐答案
MEF是要走的路。您将需要创建自己的控制器工厂,以取代默认的控制器工厂。看看这个链接。 gzak是做精。
MEF is the way to go. You will need to create your own controller factory to replace the default controller factory. Take a look at this link. http://www.fidelitydesign.net/?p=104 gzak is doing fine.
这篇关于ASP.Net的WebAPI:如何加载运行时额外的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!