2013-04-02 57 views
0

请再次需要您的帮助。我正在开发一个模块化概念的应用程序。Unity&Prism模块化 - 载入问题

我想为它使用Prism和Unity。我已经看过棱镜的快速入门示例,我也在MSDN上阅读了这个article

我的实际代码如下所示:

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(); 
    } 
} 

我的配置:

<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> 

我现在有两个问题,第一个是目录未加载正确的。 对我来说,似乎加载方法没有被调用,或类似的东西。

第二个问题是第一个问题的后果,我认为我的模块中的初始化方法没有被调用。

任何人都可以帮助我吗?

回答

2

我已将您的代码放在Desktop Prism项目中,但它按预期工作。

某处在您的应用程序,你需要(至少):

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

相信对于配置部分,默认是为引导程序运行模块,在启动时,以便尽快加载,你模块应该加载并初始化。这正是我在本地发生的事情。

这是我的模块“初始化”的模样:

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

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

检查将看看是否能找到它看起来在目录中MyApp.Module1.dll,但你会得到一个ModuleTypeLoadingException最后一件事在FileNotFoundException之后,如果不是这种情况,则有一次例外。

编辑:这里是the complete source code为我所做的测试解决方案。我想不出任何使它适用于我的差异,但不适合你。一探究竟。

+0

感谢您的回复。 很抱歉忘记发布我的App.xaml.cs代码。我重写了启动并在那里启动我的引导程序。 我的模块类大多是像你的一样,我只有另一个测试字符串:-) Annd终于是该文件是在正确的文件夹,我没有得到任何异常。 但它仍然无法正常工作。 – Sukram

+0

@Sukram:这几乎是我所做的,我已经压缩了解决方案的源代码,因为我想不出任何我可能做得不同的事情。 – Thorarin

+0

@ Thorarin:感谢你的代码,我没有发现任何对我的代码的决定性,但它的工作原理。我建立了一个基于你的类的新项目,现在它工作正常。感谢您的帮助和代码示例。 – Sukram