Prism w/Mef 自举问题

发布于 2024-10-06 16:50:44 字数 1672 浏览 2 评论 0原文

我有一个可以正常工作的参考应用程序,但现在坏了,我不明白为什么。给我带来问题的代码基本上是 Prism 的 ModularityWithMef 快速入门示例的精确副本。除了添加我的模块发现逻辑之外,引导模块是快速入门的精确副本。所以我不把它包括在这里。我在 Shell 的视图代码后面遇到的问题是来自快速入门的 Shell 代码后面的几乎完全相同的副本。代码是 -

namespace MvvmRefVer
{
    using System.ComponentModel;
    using System.ComponentModel.Composition;
    using System.Diagnostics;
    using System.Globalization;
    using System.Windows;

    using Microsoft.Practices.Prism.Logging;
    using Microsoft.Practices.Prism.Modularity;

    [Export]
    public partial class Shell : Window, IPartImportsSatisfiedNotification
    {
        [Import(AllowRecomposition = false)]
        private CallbackLogger logger;

        [Import(AllowRecomposition = false)]
        private IModuleManager moduleManager;

        public Shell()
        {
            this.InitializeComponent();
        }

        public void OnImportsSatisfied()
        {
        }
        private void WindowClosing(object sender, CancelEventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            this.moduleManager.LoadModule("NavigationViewControlModule");
        }
    }

问题发生在这个函数 Bootstrapper -

    protected override DependencyObject CreateShell()
    {
        var d =  this.Container.GetExportedValue<Shell>();
        return d;
    }

当调用 GetExportedValue 并且 [Import(AllowRecomposition = false)] 上面的 moduleManager 定义存在时,函数调用将生成一个未定义的异常。如果我注释掉 Import 行,Shell 将正确加载,但不会初始化 moduleManager。

我的问题是我没有足够的 MEF 经验来了解问题所在。在查看 mef 目录时,我可以看到 Prism Modularity 库已加载。

I have a reference application that was working and now is broke and I cannot figure out why. The code that is giving me the problem is basically an exact copy of Prism's ModularityWithMef Quickstart example. The bootstrap module is an exact copy of the Quickstart except for adding my module discovery logic. So I'm not including that here. The problem I'm having in the Shell's View code behind with is an almost exact copy from the QuickStart's Shell Codebehind. The code is -

namespace MvvmRefVer
{
    using System.ComponentModel;
    using System.ComponentModel.Composition;
    using System.Diagnostics;
    using System.Globalization;
    using System.Windows;

    using Microsoft.Practices.Prism.Logging;
    using Microsoft.Practices.Prism.Modularity;

    [Export]
    public partial class Shell : Window, IPartImportsSatisfiedNotification
    {
        [Import(AllowRecomposition = false)]
        private CallbackLogger logger;

        [Import(AllowRecomposition = false)]
        private IModuleManager moduleManager;

        public Shell()
        {
            this.InitializeComponent();
        }

        public void OnImportsSatisfied()
        {
        }
        private void WindowClosing(object sender, CancelEventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            this.moduleManager.LoadModule("NavigationViewControlModule");
        }
    }

The problem occurs in this function Bootstrapper -

    protected override DependencyObject CreateShell()
    {
        var d =  this.Container.GetExportedValue<Shell>();
        return d;
    }

When the GetExportedValue is called and [Import(AllowRecomposition = false)] above definition of moduleManager is present, the function call will generate an Undefined Exception. If I comment out the Import line, the Shell will load properly, but without initializing the moduleManager.

My problem is that I don't have enough experience with MEF to understand what the problem is. While looking at the mef catalogs, I can see that the Prism Modularity library has been loaded.

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

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

发布评论

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

评论(1

懒的傷心 2024-10-13 16:50:44

发布未定义异常的消息和堆栈跟踪会有所帮助。

有关解决 MEF 问题的一般帮助,请参阅我的博客文章 如何调试和诊断 MEF 故障

Posting the message and the stack trace of the Undefined Exception would help.

For general help in figuring out MEF problems, see my blog post on How to Debug and Diagnose MEF Failures.

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