2013-07-04 2 views
0

최근 PRISM WPF 응용 프로그램을 개발하는 데 관심이있었습니다. 이제 모듈 프로젝트 (Wpf User Control Library)를 빌드 한 후 만든 DLL에서 모듈을로드하려고합니다. modules 프로젝트를 빌드하는 동안 DLL을 디버그 폴더에 복사합니다 (복사 : xcopy/y "$ (TargetPath)" "$ (SolutionDir) FooBar \ $ (OutDir) Modules \"). 다음으로 부트 스트 래퍼를 구성하고 잃어버린 것이 있다고 생각합니다.DLL에서 프리즘 모듈로드

아래 코드를 첨부하겠습니다.

스트 래퍼

public class Bootstrapper : UnityBootstrapper 
{ 
    protected override DependencyObject CreateShell() 
    { 
     var shell = ServiceLocator.Current.GetInstance<Shell>(); 
     return shell; 
    } 

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

     App.Current.MainWindow = (Window)this.Shell; 
     App.Current.MainWindow.Show(); 
    } 

    protected override IModuleCatalog CreateModuleCatalog() 
    { 
     return base.CreateModuleCatalog(); 
    } 

    protected override void ConfigureModuleCatalog() 
    { 
     var moduleCatalog = new DirectoryModuleCatalog(); 
     moduleCatalog.ModulePath = Environment.CurrentDirectory + @"\Modules"; 
     ModuleCatalog = moduleCatalog; 
    } 

    protected override void InitializeModules() 
    { 
     base.InitializeModules(); 
    } 

    protected override ILoggerFacade CreateLogger() 
    { 
     return base.CreateLogger(); 
    } 
} 

Shell.xaml.cs

protected readonly IModuleCatalog _moduleCatalog; 

    public Shell(IModuleCatalog moduleCatalog) 
    { 
     this._moduleCatalog = moduleCatalog; 
     InitializeComponent(); 
    } 

App.xaml.cs를

public partial class App : Application 
    { 
    protected override void OnStartup(StartupEventArgs e) 
    { 
     base.OnStartup(e); 

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

ViewModelBase

public abstract class ViewModelBase : INotifyPropertyChanging, INotifyPropertyChanged,IModule 
    { 

     //Implementation INotify etc.. 

    public void Initialize() 
    { 

    } 
} 

그래서 ModuleCatalog.Modules이 항상 0인지 궁금합니다. 누군가 나를 도울 수 있습니까?

+0

필자와 같이 디렉터리 기술을 사용하지만 디렉터리는 지정하지 마십시오. * 그러나 모듈은 부트 스트 래퍼가 들어있는 어셈블리와 동일한 디렉토리에 있어야합니다! 그것은 내가 살아서 행복해하는 제약입니다. –

+0

moduleCatalog.Initialize();를 추가해야했습니다. 프리즘에 대한 ConfigureModuleCatalog에 모든 모듈을 찾습니다. – Rtype

답변

1

모듈 카탈로그가 null입니까? 또는 모듈이 포함되어 있지 않습니까? Environment.CurrentDirectory + @ "\ Modules"을 확인하십시오. 올바른 경로를 반환하고 모든 DLL이 있습니다. 정말 dir에서로드해야합니까? 어떤 모듈이로드 될지 모르십니까?

내가 그렇게하는 데는 보통 :

public partial class Bootstrapper: UnityBootstrapper 
{ 
    protected override void ConfigureContainer() 
    { 
     base.ConfigureContainer(); 
    } 

    protected override IModuleCatalog CreateModuleCatalog() 
    { 
     // Create the module catalog from a XAML file. 
     return Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(new Uri("/Shell;component/ModuleCatalog.xaml", UriKind.Relative)); 
    } 

    protected override DependencyObject CreateShell() 
    { 
     // Use the container to create an instance of the shell. 
     ShellView view = Container.TryResolve<ShellView>(); 

     // Display the shell's root visual. 
     //view.ShowActivated = false; 
     view.Show(); 

     return view; 
    } 
} 

내 modulecatalog을

<prism:ModuleCatalog xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:sys="clr-namespace:System;assembly=mscorlib" 
xmlns:prism="clr-namespace:Microsoft.Practices.Prism.Modularity;assembly=Microsoft.Practices.Prism"> 




<prism:ModuleInfo Ref="Connexion.dll" 
        ModuleName="Connexion" 
        ModuleType="Connexion.ModuleInit, Connexion, Version=1.0.0.0" /> 

<prism:ModuleInfo Ref="Tools.dll" 
        ModuleName="Tools" 
        ModuleType="Tools.ModuleInit, Tools, Version=1.0.0.0" /> 


<prism:ModuleInfo Ref="DrawingModule.dll" 
        ModuleName="DrawingModule" 
        ModuleType="DrawingModule.ModuleInit, DrawingModule, Version=1.0.0.0" 
        InitializationMode="WhenAvailable"> 
    <prism:ModuleInfo.DependsOn> 
     <sys:String>Connexion</sys:String> 
     <sys:String>Tools</sys:String> 
    </prism:ModuleInfo.DependsOn> 
</prism:ModuleInfo> 



<prism:ModuleInfo Ref="Sis.dll" 
        ModuleName="Sis" 
        ModuleType="Sis.ModuleInit, Sis, Version=1.0.0.0" 
        InitializationMode="WhenAvailable"> 
    <prism:ModuleInfo.DependsOn> 
     <sys:String>Connexion</sys:String> 
     <sys:String>Tools</sys:String> 
     <sys:String>DrawingModule</sys:String> 
    </prism:ModuleInfo.DependsOn> 
</prism:ModuleInfo> 

모든 모듈은 buildAction 있습니다 사본을 "$ (있는 TargetPath)" "$ (SolutionDir) 쉘 \ $ (OutDir) "

+0

동일한 DLL에 모든 모듈을 가지고 있어도 동일한 결과를 얻을 수 있습니까? –

+0

dll에 다중 어셈블리 이름이 있고 여러 모듈 초기화가있는 경우를 제외하고는 가능하지 않다고 생각합니다.하지만 보이지도 깨끗하지도 않고 좋지도 않습니다. – Enhakiel

+0

입력 해 주셔서 감사합니다. –