Asp.net MVC - 异步控制器从我的基本控制器获取功能
我有一个基本控制器,它是标准 mvc 控制器的子类。它包含许多特定于控制器的有用方法。
我现在需要在我的一个新控制器中具有一些异步功能
但是,要做到这一点,您需要创建一个子类 AsyncController 的控制器
但我也想访问我的基本控制器中的功能
显然多重继承是不可能的
,所以我该如何做解决这个问题吗?
I have a base controller which is subclassed from a standard mvc controller. This containers lots of useful methods specific to a Controller.
I now need to have some asych functionality in one of my new controllers
However, to do that you need to create a controller that subclasses AsyncController
But I also want to access functionality in my base controller
Obviously multiple inheritance isn't possible
so how do I get around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将您愿意重用的功能外部化到服务层、操作过滤器、授权过滤器、模型绑定器中......这将取决于您愿意重用的功能,以便您可以轻松地将基本控制器切换为异步控制器并仍然保留功能。如果您想使用异步控制器,您需要从 派生异步控制器。
You could externalize the functionality you are willing to reuse into a service layer, action filter, authorization filter, model binder, ... it will depend on the functionality you are willing to reuse so that you could easily switch the base controller to an async controller and still preserve the functionality. If you want to use async controllers you will need to derive from AsyncController.
您可以让您的控制器类继承
IAsyncManagerContainer
和IAsyncController
,然后自己实现此功能,也许使用 MVC 源代码中的代码。您甚至可以将其封装在您将功能委托给的自己的类中。You could make your controller class inherit
IAsyncManagerContainer
andIAsyncController
, then implement this functionality yourself, perhaps using the code from MVC source code. You could even encapsulate this in its own class that you delegate the functionality to.