团结与Prism Modularity - 负载问题 [英] Unity & Prism Modularity - Load problems

查看:53
本文介绍了团结与Prism Modularity - 负载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我再次需要你的帮助.我正在开发一个具有模块化概念的应用程序.

我想为此使用 Prism 和 Unity.我看过 Prism 的快速入门示例,我还阅读了这个 文章.

我的实际代码如下:

公共类 Bootstrapper : UnityBootstrapper{受保护的覆盖 DependencyObject CreateShell(){返回 this.Container.Resolve();}protected override void InitializeShell(){base.InitializeShell();var window = this.Shell as Window;如果(窗口!= null){Application.Current.MainWindow = 窗口;}别的{throw new ArgumentException("外壳必须是一个窗口.");}}受保护的覆盖 IModuleCatalog CreateModuleCatalog(){返回新的 ConfigurationModuleCatalog();}}

我的配置:

<预><代码><配置><configSections><部分名称=模块"type="Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism"/></configSections><模块><module assemblyFile="Modules/MyApp.Module1.dll"moduleType="MyApp.Module1.Module1Module, MyApp.Module1"moduleName="Module1"/></模块><启动><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></启动></配置>

我现在有两个问题,第一个是目录没有加载对.对我来说,似乎没有调用 load 方法,或者类似的东西.

第二个问题是我认为第一个问题的结果,我的模块中的 initialize 方法没有被调用.

有人可以帮我吗?

解决方案

我在 Desktop Prism 项目中采用了您的代码,但它按预期工作.

在您的应用程序中,您将需要(至少):

var bootstrapper = new Bootstrapper();bootstrapper.Run();

我相信对于 config 部分,默认是模块在启动时加载,所以只要 Bootstrapper 运行,你的模块就应该被加载和初始化.这正是我在本地发生的情况.

这是我的模块初始化"的样子:

使用系统;使用 System.Windows;使用 Microsoft.Practices.Prism.Modularity;命名空间 MyApp.Module1{类 Module1Module : IModule{公共无效初始化(){MessageBox.Show("你好世界!");}}}

要检查的最后一件事是查看它是否可以在它正在查找的目录中找到 MyApp.Module1.dll,但之后您会得到一个 ModuleTypeLoadingException如果不是这种情况,则为 FileNotFoundException 第一次机会异常.

这里是完整的源代码 用于我制作的测试解决方案.我想不出有什么区别使它对我有用,但对你却不起作用.看看吧.

I need your help again please. I am working on a application with a modular concept.

I want to use Prism and Unity for it. I have looked at the quickstart example from Prism and I also read this article on MSDN.

My actual code looks like:

public class Bootstrapper : UnityBootstrapper
{
    protected override DependencyObject CreateShell()
    {
        return this.Container.Resolve<Shell>();
    }

    protected override void InitializeShell()
    {
        base.InitializeShell();

        var window = this.Shell as Window;
        if (window != null)
        {
            Application.Current.MainWindow = window;
        }
        else
        {
            throw new ArgumentException("The shell has to be a window.");
        }
    }


    protected override IModuleCatalog CreateModuleCatalog()
    {
        return new ConfigurationModuleCatalog();
    } 
}

My config:

<configuration>
  <configSections>
    <section name="modules" 
             type="Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism"/>
  </configSections>
  <modules>
    <module assemblyFile="Modules/MyApp.Module1.dll"
            moduleType="MyApp.Module1.Module1Module, MyApp.Module1"
            moduleName="Module1" />
  </modules>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
</configuration>

I have now two problems, the first is that the catalog is not loaded right. For me it seems that the load method is not being called, or something like that.

The second problem is a consequence of the first I think, that the initialize method in my module is not called.

Can anybody help me?

解决方案

I've taken your code as is in a Desktop Prism project, but it works as expected.

Somewhere in your application, you will need (at minimum):

var bootstrapper = new Bootstrapper();
bootstrapper.Run();

I believe for the config section, the default is for modules to load on startup, so as soon as the Bootstrapper runs, your module should be loaded and initialized. This is exactly what happens for me locally.

This is what my module "initialization" looks like:

using System;
using System.Windows;
using Microsoft.Practices.Prism.Modularity;

namespace MyApp.Module1
{
    class Module1Module : IModule
    {
        public void Initialize()
        {
            MessageBox.Show("Hello world!");
        }
    }
}

One last thing to check would be to see if it can find the MyApp.Module1.dll in the directory it's looking in, but you would get a ModuleTypeLoadingException after a FileNotFoundException first-chance exception if this wasn't the case.

Edit: here is the complete source code for the test solution I made. I cannot think of any differences that make it work for me, but not for you. Check it out.

这篇关于团结与Prism Modularity - 负载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆