2012-01-09 101 views
1

當在棱鏡/ WPF設置模塊,使用棱鏡模塊化:什麼是moduleType(和moduleName)?

<section name="modules" type="Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism" 

...有app.config文件中,在這裏你可以添加每個模塊,這樣的部分:

<module assemblyFile="MyCompany.ABC.Client.Module.OutlookBar.dll" 
moduleType="MyCompany.ABC.Client.Module.OutlookBarModule.OutlookBarModule,  
MyCompany.ABC.Client.Module.OutlookBar" moduleName="OutlookBarModule" 
startupLoaded="true"/> 

此代碼有效,但我真的很想知道更多關於moduleType屬性的信息。它由什麼組成?

起初我以爲是namespace.classname + comma + namespace。 (即完全合格的類名,命名空間(無類名)

但圍繞在我的OutlookBar「主類」的命名空間被命名爲這樣的: MyCompany.ABC.Client.Module.OutlookBarModule 和它的類名是「OutlookBarModule」

那麼...... moduleType定義的第二部分(在逗號後面)???我找不到這個名稱(「MyCompany.ABC.Client.Module.OutlookBar 「)在我的代碼中,除了程序集名稱外。

此致敬意, Andreas

+0

我的問題標題表明我也有一個關於moduleName的問題,但我忘了寫這個問題。我在另一個地方發現,「默認情況下,當未指定模塊名稱時,類名稱將用作模塊名稱」。這可能是正確的。 – 2012-01-10 12:44:05

回答

2

這是程序集名稱(沒有文件擴展名,可能是.exe或.dll)。這是通過.NET中的配置引用類的常見模式:「namespace.classname,assemblyname」。

+0

看來它可能不僅僅是程序集名稱。我正在查看指定ModuleType屬性中的IModule實現類的模塊目錄: ModuleType =「MyProject.ModuleInit,MyProject,Version = 1.0.0.0」 – ArturPhilibin 2012-01-20 14:39:45

+0

是的,但OP詢問的部分只是組件名稱。你在那裏有Namespace.Classname,AssemblyName,版本 – 2012-01-20 14:51:44

+0

啊我看到了,我的錯誤 – ArturPhilibin 2012-01-20 15:30:30

0

也許是你說什麼,集名稱,因爲它是一個完全合格的名稱省略版本,文化,...

看看MSDN

0

在棱鏡4 ModuleType屬性是實現IModule的一個類型,通常是一個在每個項目

棱鏡的ModuleInitializer.cs稱爲ModuleInit類的程序集限定名稱顯示如下:

protected virtual IModule CreateModule(ModuleInfo moduleInfo) 
{ 
    if (moduleInfo == null) throw new ArgumentNullException("moduleInfo"); 

    //Below Prism is passing the ModuleType property 
    return this.CreateModule(moduleInfo.ModuleType); 
} 

protected virtual IModule CreateModule(string typeName) 
{ 
    Type moduleType = Type.GetType(typeName); 
    if (moduleType == null) 
    { 
     throw new ModuleInitializeException(
      string.Format(CultureInfo.CurrentCulture, 
      Properties.Resources.FailedToGetType, typeName)); 
    } 

    //and then that type is cast to IModule 
    return (IModule)this.serviceLocator.GetInstance(moduleType); 
}