I feel I have seen this question asked a lot, but most of the tutorials/examples I have seen are outdated as the UnityBootstrapper
class is obsolete and seems to be depreciated. I can only seem to find PrismBootstrapper
which does not implement the same features as UnityBootstrapper
.
Can someone give me an example of how to use PrismBootstrapper
or maybe point out what I am doing wrong with trying to derive from the UnityBootstrapper
?
I am trying to following this tutorial: https://www.c-sharpcorner.com/blogs/creating-a-first-wpf-application-using-prism-library-and-mvvm-architectural-patternstep-by-step2
EDIT: This is what I needed to get the MVVM Prism.Unity with Bootstrapper to work. I didn't understand how to configure the IModuleCatalog or RegisterTypes properly. I still don't quite understand what RegisterTypes does or how to use the Interfaces I have registered.
I Created 2 projects. The Main Project (WPF app (.NET Framework)) called MRC and AlertsLogger.
Here is the code for my bootstrapper. This is setup to run at runtime instead of opening to a window.
using System;
using System.Windows;
using AlertsLogger.Interfaces;
using MRC.Framework.Core.Data.Connectivity;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Unity;
using Unity;
namespace MRC
{
[Obsolete]
public class BootStrapper : PrismBootstrapper
{
#region Override Methods
protected override DependencyObject CreateShell()
{
return Container.Resolve<Shell>();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterInstance<IListener>(new Listener());
containerRegistry.RegisterInstance<IConnectionProvider>(new ConnectionProvider());
containerRegistry.RegisterInstance<ISettingsProvider>(new SettingsProvider());
}
protected override void InitializeShell(DependencyObject shell)
{
base.InitializeShell(shell);
App.Current.MainWindow = (Window)shell;
App.Current.MainWindow.Show();
}
protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
{
base.ConfigureModuleCatalog(moduleCatalog);
Type ModuleLocatorType = typeof(AlertsLogger.ModuleLocators);
moduleCatalog.AddModule(new Prism.Modularity.ModuleInfo
{
ModuleName = ModuleLocatorType.Name,
ModuleType = ModuleLocatorType.AssemblyQualifiedName
});
}
#endregion
}
}
- In the AlertsLogger project I had to create a class called ModuleLocators.
public class ModuleLocators : IModule
{
#region private properties
/// <summary>
/// Instance of IRegionManager
/// </summary>
private IRegionManager _regionManager;
#endregion
#region Constructor
/// <summary>
/// parameterized constructor initializes IRegionManager
/// </summary>
/// <param name="regionManager"></param>
public ModuleLocators(IRegionManager regionManager)
{
_regionManager = regionManager;
}
#endregion
#region Interface methods
/// <summary>
/// Initializes Welcome page of your application.
/// </summary>
/// <param name="containerProvider"></param>
public void OnInitialized(IContainerProvider containerProvider)
{
_regionManager.RegisterViewWithRegion("Shell", typeof(Views.LoggerDataView));
}
/// <summary>
/// RegisterTypes used to register modules
/// </summary>
/// <param name="containerRegistry"></param>
public void RegisterTypes(IContainerRegistry containerRegistry)
{
}
#endregion
}