Asp.net MVC - 异步控制器从我的基本控制器获取功能

发布于 2024-10-31 00:11:54 字数 202 浏览 3 评论 0原文

我有一个基本控制器,它是标准 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝颜夕 2024-11-07 00:11:54

您可以将您愿意重用的功能外部化到服务层、操作过滤器、授权过滤器、模型绑定器中......这将取决于您愿意重用的功能,以便您可以轻松地将基本控制器切换为异步控制器并仍然保留功能。如果您想使用异步控制器,您需要从 派生异步控制器

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.

晨与橙与城 2024-11-07 00:11:54

您可以让您的控制器类继承 IAsyncManagerContainerIAsyncController,然后自己实现此功能,也许使用 MVC 源代码中的代码。您甚至可以将其封装在您将功能委托给的自己的类中。

You could make your controller class inherit IAsyncManagerContainer and IAsyncController, 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文