I am building a WPF Application using Prism and Unity.
I have a module that should not be used by everyone, so I want to build it that the program starts without the module dll, but when I copy the module dll to the output folder and restart the program, the module should be loaded.
I am using a XamlModuleCatalog:
<Modularity:ModuleCatalog
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Modularity="clr-namespace:Prism.Modularity;assembly=Prism.Wpf">
<Modularity:ModuleInfo
Ref="file://TrayManager.UI.dll"
ModuleName="UIModule"
ModuleType="TrayManager.UI.UIModule, TrayManager.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Modularity:ModuleInfo
Ref="file://TrayManager.PasswordEncryption.dll"
InitializationMode="OnDemand"
ModuleName="PasswordEncryptionModule"
ModuleType="TrayManager.PasswordEncryption.PasswordEncryptionModule, TrayManager.PasswordEncryption, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</Modularity:ModuleCatalog>
When I set the InitializationMode of my PasswordEncryptionModule to 'OnDemand', it will never be loaded, but the program starts.
When I set the InitializationMode to 'WhenAvailable' the program only starts if the dll is in the output folder.
In my App.xaml.cs:
protected override Window CreateShell()
{
_logger.Debug("Shell created");
return Container.Resolve<MainWindow>();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
}
protected override IModuleCatalog CreateModuleCatalog() {
return new XamlModuleCatalog(new Uri("/TrayManager;component/ModuleCatalog.xaml", UriKind.Relative));
}
What am I doing wrong?
CodePudding user response:
The DirectoryModuleCatalog
loads all the modules it finds in a given folder which makes it a good fit if the modules are deployed independent of the application or vary over time.