我创建使用ASP.NET MVC(2)和Spring.NET的应用程序。ASP.NET MVC的通用控制器和Spring.NET
由于大多数我的控制器实现的只是实现类似的CRUD操作,我想只需要创建一个单一的通用控制器,如下解释:
In asp.net mvc is it possible to make a generic controller?
然而,上面的例子中没有考虑DI框架考虑在内。
我在想什么是创建这个(警告:这是代码的丑陋质量我需要帮助):
public SpringGenericControllerFactory : DefaultControllerFactory {
public IController CreateController(RequestContext requestContext, string controllerName) {
// Determine the controller type to return
Type controllerType = Type.GetType("MyController").MakeGenericType(Type.GetType(controllerName));
// Return the controller
return Activator.CreateInstance(controllerType) as IController;
}
}
在objects.xml的条目将是这个样子:
<object id="controllerFactory" type="Application.Controllers.SpringGenericControllerFactory" />
<object id="DepartmentController" factory-method="CreateController" factory-object="controllerFactory" />
任何人都可以通过挑选这并提供建议?