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框架 加载图片 库 Picasso 的使用简介

    0 说明 现在Android开源库中有许多图片加载框架,本文以picasso为例,总结下开发过程中的一些优化经验,使用的picasso版本如下 compile 'com.squareup.picass ...

  2. 从手工测试转型web自动化测试继而转型成专门做自动化测试的学习路线。

    在开始之前先自学两个工具商业web自动化测试工具请自学QTP:QTP的学习可以跳过,我是跳过了的.开源web自动化测试工具请自学Selenium:我当年是先学watir(耗时1周),再学seleniu ...

  3. SICP 1.1-1.5

    1.1 a = b = nil 1.2 (/ (+ (- (- (+ (/ ))))) (* (- ) (- )) 1.3 a = b = nil 1.4... 1.5 (define (p) (p) ...

  4. GLib基础

    实用功能 GLib中包含了近二十种实用功能,从简单的字符处理到初学者很难理解的XML解析功能,这里介绍两种较简单的:随机数和计时. 下面代码演示如何产生1-100之间的随机整数和演示如何计算30000 ...

  5. [mysq]ERROR 2006 (HY000) at line xx: MySQL server has gone away 解决方法

    vi /etc/my.cnf wait_timeout=2880000interactive_timeout = 2880000max_allowed_packet = 100M 完整配置文件 [my ...

  6. java基础回顾(二)——内部类

    一.常规内部类 public class Outer { int count; void say(){ count++; System.out.println("我是外部类"); ...

  7. sql语句中日期时间格式化查询

          今天在做会员管理系统搜索时,我发现以前的搜索时间方式不太科学,效率也不是太高.由其是在查询指定的时间相等的时候,我在数据库中都存这样的时间格式"2007-5-22 14:32:1 ...

  8. Windows phone 8 学习笔记(1) 触控输入(转)

    Windows phone 8 的应用 与一般的Pc应用在输入方式上最大的不同就是:Windows phone 8主要依靠触控操作.因此在输入方式上引入一套全新的触控操作方式,我们需要重新定义相关的事 ...

  9. poj2000

    为了凑今天的数,大水题.不解释了,说来惭愧. #include <stdio.h> int main(){ int n; int i,cnt,j; int tot; while(~scan ...

  10. [原]sdut2624 Contest Print Server (大水+大坑)山东省第四届ACM省赛

    本文出自:http://blog.csdn.net/svitter 原题:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&am ...