prism包含两种UnityBootstrapper and MefBootstrapper。
创建bootstrapper步骤:
1、CreateShell
方法一
protectedoverride DependencyObject CreateShell()
{
return ServiceLocator.Current.GetInstance<Shell>();
}
方法二
protectedoverride DependencyObject CreateShell()
{
Shell shell = this.Container.GetExportedValue<Shell>();
returnshell;
}
2、Implementingthe InitializeShell Method
silverlight
protectedoverride void InitializeShell()
{
Application.Current.RootVisual = Shell;
}
wpf
protectedoverride void InitializeShell()
{
Application.Current.MainWindow = Shell;
Application.Current.MainWindow.Show();
}
Thebase implementation of InitializeShell does nothing. You do not need to callthe
base class implementation.
3、Creating and Configuring the Module Catalog
protected override IModuleCatalogCreateModuleCatalog()
{
// When using MEF, the existing PrismModuleCatalog is still
// the place to configure modules viaconfiguration files.
return ModuleCatalog.CreateFromXaml(new Uri(
"/ModularityWithMef.Silverlight;component/ModulesCatalog.xaml",
UriKind.Relative));
}
4、Creating andConfiguring the Container
UnityBootstrapper
protected override void ConfigureContainer()
{
base.ConfigureContainer();
this.RegisterTypeIfMissing(typeof(IModuleTracker),typeof(ModuleTracker), true);
this.Container.RegisterInstance<CallbackLogger>(this.callbackLogger);
}
MefBootstrapper
protected override voidConfigureAggregateCatalog()
{
base.ConfigureAggregateCatalog();
// Add this assembly to export ModuleTracker
this.AggregateCatalog.Catalogs.Add(
newAssemblyCatalog(typeof(QuickStartBootstrapper).Assembly));
// Module A is referenced in the project anddirectly in code.
this.AggregateCatalog.Catalogs.Add(
newAssemblyCatalog(typeof(ModuleA.ModuleA).Assembly));
// Module C is referenced in the project anddirectly in code.
this.AggregateCatalog.Catalogs.Add(
newAssemblyCatalog(typeof(ModuleC.ModuleC).Assembly));
}