MEFContrib.MVC3:导出带有基类的控制器

发布于 2024-12-03 03:44:18 字数 852 浏览 3 评论 0原文

我在 CodePlex 上提出了一个问题,但尚未收到任何回复。

基本上,我有一个所有控制器都继承自的基本控制器。当我创建一个新的 MVC3 项目,将控制器放入另一个程序集中,并将 MEFContrib.MVC3 添加到该项目时,一切都运行良好。当我使任何控制器继承自我的基类时,它们将不再被发现。

我对 MEFContrib 不太熟悉,不知道到底出了什么问题,但我尝试用 ExportAttribute 装饰我的控制器,但这也没有奏效。

所有这些都是与主 MVC 项目不同的程序集:

public class MyBaseController : Controller
{
    ...
}

//  This controller cannot be found.
public class HomeController : MyBaseController
{
    public ActionResult Index ()
    {
        // Do Stuff
        return View ();
    }
}

// This controller can be found.
public class HomeController : Controller
{
    // yada, yada, yada...
}

编辑:

coachlorben 是完全正确的。我的依赖项未正确标记为导出,因此无法正确组合控制器。我逐步检查了每个依赖项,逐步检查了它们自己的依赖项,并找到了一些我错过的项。

I have opened up a question on CodePlex but have not received any responses at all.

Basically, I have a base controller that all of my controllers inherit from. When I create a new MVC3 project, put my controllers in another assembly, and add MEFContrib.MVC3 to the project, everything works great. When I make any of the controllers inherit from my base class, they can no longer be found.

I am not familiar enough with MEFContrib to know what exactly is breaking, but I have tried to decorate my controllers with ExportAttributes and that has not worked, either.

All of this is a different assembly than the main MVC project:

public class MyBaseController : Controller
{
    ...
}

//  This controller cannot be found.
public class HomeController : MyBaseController
{
    public ActionResult Index ()
    {
        // Do Stuff
        return View ();
    }
}

// This controller can be found.
public class HomeController : Controller
{
    // yada, yada, yada...
}

Edit:

counsellorben was exactly right. I had dependencies that were not properly marked for export and so the controllers could not be properly composed. I stepped through each of my dependencies, stepping through their own dependencies, and found the few I missed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

淡写薰衣草的香 2024-12-10 03:44:18

最可能的问题是 MyController 类中的依赖项存在问题。这将导致任何继承自 MyController 的控制器出现问题。

请参阅此答案,获取一些示例代码,您可以使用它来尝试诊断问题所在谎言。

The most likely issue is that there is a problem with a dependency in your MyController class. This will cause a problem with any controller inheriting from MyController.

Please see this answer for some sample code you can use to try and diagnose where your problem lies.

寄离 2024-12-10 03:44:18

我认为您需要用 InheritedExport 属性进行装饰。

I think you need to decorate with the InheritedExport attribute.

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