Prism框架需要在应用程序启动的时候进行一些初始化的工作,Bootstrapper就是来做这些的,是其切入点。

Bootstrapper主要要做的事有:创建和配置module catalog,创建DI Container,为UI配置默认的region适配器,创建和初始化shell以及初始化module。

    /// <summary>
/// Base class that provides a basic bootstrapping sequence and hooks
/// that specific implementations can override
/// </summary>
/// <remarks>
/// This class must be overridden to provide application specific configuration.
/// </remarks>
public abstract class Bootstrapper
{
/// <summary>
/// Gets the <see cref="ILoggerFacade"/> for the application.
/// </summary>
/// <value>A <see cref="ILoggerFacade"/> instance.</value>
protected ILoggerFacade Logger { get; set; } /// <summary>
/// Gets the default <see cref="IModuleCatalog"/> for the application.
/// </summary>
/// <value>The default <see cref="IModuleCatalog"/> instance.</value>
protected IModuleCatalog ModuleCatalog { get; set; } /// <summary>
/// Gets the shell user interface
/// </summary>
/// <value>The shell user interface.</value>
protected DependencyObject Shell { get; set; } /// <summary>
/// Create the <see cref="ILoggerFacade" /> used by the bootstrapper.
/// </summary>
/// <remarks>
/// The base implementation returns a new TextLogger.
/// </remarks>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "The Logger is added to the container which will dispose it when the container goes out of scope.")]
protected virtual ILoggerFacade CreateLogger()
{
return new TextLogger();
} /// <summary>
/// Runs the bootstrapper process.
/// </summary>
public void Run()
{
this.Run(true);
} /// <summary>
/// Creates the <see cref="IModuleCatalog"/> used by Prism.
/// </summary>
/// <remarks>
/// The base implementation returns a new ModuleCatalog.
/// </remarks>
protected virtual IModuleCatalog CreateModuleCatalog()
{
return new ModuleCatalog();
} /// <summary>
/// Configures the <see cref="IModuleCatalog"/> used by Prism.
/// </summary>
protected virtual void ConfigureModuleCatalog()
{
} /// <summary>
/// Registers the <see cref="Type"/>s of the Exceptions that are not considered
/// root exceptions by the <see cref="ExceptionExtensions"/>.
/// </summary>
protected virtual void RegisterFrameworkExceptionTypes()
{
ExceptionExtensions.RegisterFrameworkExceptionType(
typeof(Microsoft.Practices.ServiceLocation.ActivationException));
} /// <summary>
/// Initializes the modules. May be overwritten in a derived class to use a custom Modules Catalog
/// </summary>
protected virtual void InitializeModules()
{
IModuleManager manager = ServiceLocator.Current.GetInstance<IModuleManager>();
manager.Run();
} /// <summary>
/// Configures the default region adapter mappings to use in the application, in order
/// to adapt UI controls defined in XAML to use a region and register it automatically.
/// May be overwritten in a derived class to add specific mappings required by the application.
/// </summary>
/// <returns>The <see cref="RegionAdapterMappings"/> instance containing all the mappings.</returns>
protected virtual RegionAdapterMappings ConfigureRegionAdapterMappings()
{
RegionAdapterMappings regionAdapterMappings = ServiceLocator.Current.GetInstance<RegionAdapterMappings>();
if (regionAdapterMappings != null)
{
regionAdapterMappings.RegisterMapping(typeof(Selector), ServiceLocator.Current.GetInstance<SelectorRegionAdapter>());
regionAdapterMappings.RegisterMapping(typeof(ItemsControl), ServiceLocator.Current.GetInstance<ItemsControlRegionAdapter>());
regionAdapterMappings.RegisterMapping(typeof(ContentControl), ServiceLocator.Current.GetInstance<ContentControlRegionAdapter>());
} return regionAdapterMappings;
} /// <summary>
/// Configures the <see cref="IRegionBehaviorFactory"/>.
/// This will be the list of default behaviors that will be added to a region.
/// </summary>
protected virtual IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()
{
var defaultRegionBehaviorTypesDictionary = ServiceLocator.Current.GetInstance<IRegionBehaviorFactory>(); if (defaultRegionBehaviorTypesDictionary != null)
{
defaultRegionBehaviorTypesDictionary.AddIfMissing(BindRegionContextToDependencyObjectBehavior.BehaviorKey,
typeof(BindRegionContextToDependencyObjectBehavior)); defaultRegionBehaviorTypesDictionary.AddIfMissing(RegionActiveAwareBehavior.BehaviorKey,
typeof(RegionActiveAwareBehavior)); defaultRegionBehaviorTypesDictionary.AddIfMissing(SyncRegionContextWithHostBehavior.BehaviorKey,
typeof(SyncRegionContextWithHostBehavior)); defaultRegionBehaviorTypesDictionary.AddIfMissing(RegionManagerRegistrationBehavior.BehaviorKey,
typeof(RegionManagerRegistrationBehavior)); defaultRegionBehaviorTypesDictionary.AddIfMissing(RegionMemberLifetimeBehavior.BehaviorKey,
typeof(RegionMemberLifetimeBehavior)); defaultRegionBehaviorTypesDictionary.AddIfMissing(ClearChildViewsRegionBehavior.BehaviorKey,
typeof(ClearChildViewsRegionBehavior)); defaultRegionBehaviorTypesDictionary.AddIfMissing(AutoPopulateRegionBehavior.BehaviorKey,
typeof(AutoPopulateRegionBehavior));
} return defaultRegionBehaviorTypesDictionary;
} /// <summary>
/// Initializes the shell.
/// </summary>
protected virtual void InitializeShell()
{
} /// <summary>
/// Run the bootstrapper process.
/// </summary>
/// <param name="runWithDefaultConfiguration">If <see langword="true"/>, registers default
/// Prism Library services in the container. This is the default behavior.</param>
public abstract void Run(bool runWithDefaultConfiguration); /// <summary>
/// Creates the shell or main window of the application.
/// </summary>
/// <returns>The shell of the application.</returns>
/// <remarks>
/// If the returned instance is a <see cref="DependencyObject"/>, the
/// <see cref="Bootstrapper"/> will attach the default <see cref="IRegionManager"/> of
/// the application in its <see cref="RegionManager.RegionManagerProperty"/> attached property
/// in order to be able to add regions by using the <see cref="RegionManager.RegionNameProperty"/>
/// attached property from XAML.
/// </remarks>
protected abstract DependencyObject CreateShell(); /// <summary>
/// Configures the LocatorProvider for the <see cref="Microsoft.Practices.ServiceLocation.ServiceLocator" />.
/// </summary>
protected abstract void ConfigureServiceLocator();
}

  

《Prism 5.0源码走读》Bootstrapper的更多相关文章

  1. 《Prism 5.0源码走读》Prism 5.0简介

    Prism是一个开发和设计模块化WPF应用的基础框架,里面包含了MVVM pattern和设计示例.当前最新的版本是Prism 5.0,官方网站:https://compositewpf.codepl ...

  2. 《Prism 5.0源码走读》ModuleCatalog

    概念 ModuleCatalog 是Prism中主要概念之一,主要用来保存应用程序可用的modules(模块),每个module都是用ModuleInfo来定义(包含module的名称.类型和位置). ...

  3. 《Prism 5.0源码走读》UnityBootstrapper

    UnityBootstrapper (abstract class)继承自Bootstrapper(abstract)类, 在Prism.UnityExtensions.Desktop project ...

  4. 《Prism 5.0源码走读》Service Locator Pattern

    在Prism Bootstrapper里面取实例的时候使用 ServiceLocator模式,使用的是CommonServiceLocator库 (http://commonservicelocato ...

  5. 《Prism 5.0源码走读》 设计模式

    Prism或Prism构建的应用程序时会使用大量的设计模式,本文简要列举Prism相关的那些设计模式. Adapter(适配器模式):Prism Library主要在Region和IoC contai ...

  6. Apache Spark源码走读之23 -- Spark MLLib中拟牛顿法L-BFGS的源码实现

    欢迎转载,转载请注明出处,徽沪一郎. 概要 本文就拟牛顿法L-BFGS的由来做一个简要的回顾,然后就其在spark mllib中的实现进行源码走读. 拟牛顿法 数学原理 代码实现 L-BFGS算法中使 ...

  7. Apache Spark源码走读之16 -- spark repl实现详解

    欢迎转载,转载请注明出处,徽沪一郎. 概要 之所以对spark shell的内部实现产生兴趣全部缘于好奇代码的编译加载过程,scala是需要编译才能执行的语言,但提供的scala repl可以实现代码 ...

  8. Apache Spark源码走读之13 -- hiveql on spark实现详解

    欢迎转载,转载请注明出处,徽沪一郎 概要 在新近发布的spark 1.0中新加了sql的模块,更为引人注意的是对hive中的hiveql也提供了良好的支持,作为一个源码分析控,了解一下spark是如何 ...

  9. Apache Spark源码走读之7 -- Standalone部署方式分析

    欢迎转载,转载请注明出处,徽沪一郎. 楔子 在Spark源码走读系列之2中曾经提到Spark能以Standalone的方式来运行cluster,但没有对Application的提交与具体运行流程做详细 ...

随机推荐

  1. Android中常用的5大布局详述

    Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面. 所有的布局方式都可以归类为ViewGroup的 ...

  2. python核心编程 第二天

    1.标准输入输出: import sys saveout=sys.stdout#保存当前输出状态 logfile=open('E://log.txt','r')# 打开文件 sys.stdout=lo ...

  3. PMP考试--价值工程法

    如果你对项目管理.系统架构有兴趣,请加微信订阅号"softjg",加入这个PM.架构师的大家庭 ValueEngineering,简称VE,是降低成本提高经济效益的有效方法,价值工 ...

  4. 学习总结 java 输入输出流

    思维导图 代码实际演示 package com.hanqi.io; import java.io.*; public class Test1 { public static void main(Str ...

  5. 学习练习 java 二分查找法

    package com.hanqi; import java.util.*; public class Test5 { public static void main(String[] args) { ...

  6. Sco Openserver下 配置SSH服务(图解)

    Sco Openserver下 配置SSH服务 好久没玩儿Sco Unix系统了,春节过后为邮政系统的一个朋友调试系统( 装了个远程服务) ,这两天将安装过程回忆了一下,总结出来给大家分享. 本试验需 ...

  7. Windows Socket网络编程-2016.01.07

    在使用WSAEventSelect的套接字模型中,遇到了WSAEventSelect返回10038的错误,在定位解决的过程中,简单记录一些定位解决的手段摘要. 使用windows的错误帮助信息,使用命 ...

  8. Java中可变长参数的使用及注意事项

    在Java5 中提供了变长参数(varargs),也就是在方法定义中可以使用个数不确定的参数,对于同一方法可以使用不同个数的参数调用,例如print("hello");print( ...

  9. 重装linux后

    root帐号解禁vi /etc/pam.d/gdmvi /etc/pam.d/gdm-passwd 两个装机必备软件源http://download1.rpmfusion.org/nonfree/fe ...

  10. Windows系统错误代码大全

    1 Microsoft Windows 系统错误代码简单分析: 0000 操作已成功完成.0001 错误的函数. 0002 系统找不到指定的文件. 0003 系统找不到指定的路径. 0004 系统无法 ...