《Prism 5.0源码走读》Bootstrapper
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的更多相关文章
- 《Prism 5.0源码走读》Prism 5.0简介
Prism是一个开发和设计模块化WPF应用的基础框架,里面包含了MVVM pattern和设计示例.当前最新的版本是Prism 5.0,官方网站:https://compositewpf.codepl ...
- 《Prism 5.0源码走读》ModuleCatalog
概念 ModuleCatalog 是Prism中主要概念之一,主要用来保存应用程序可用的modules(模块),每个module都是用ModuleInfo来定义(包含module的名称.类型和位置). ...
- 《Prism 5.0源码走读》UnityBootstrapper
UnityBootstrapper (abstract class)继承自Bootstrapper(abstract)类, 在Prism.UnityExtensions.Desktop project ...
- 《Prism 5.0源码走读》Service Locator Pattern
在Prism Bootstrapper里面取实例的时候使用 ServiceLocator模式,使用的是CommonServiceLocator库 (http://commonservicelocato ...
- 《Prism 5.0源码走读》 设计模式
Prism或Prism构建的应用程序时会使用大量的设计模式,本文简要列举Prism相关的那些设计模式. Adapter(适配器模式):Prism Library主要在Region和IoC contai ...
- Apache Spark源码走读之23 -- Spark MLLib中拟牛顿法L-BFGS的源码实现
欢迎转载,转载请注明出处,徽沪一郎. 概要 本文就拟牛顿法L-BFGS的由来做一个简要的回顾,然后就其在spark mllib中的实现进行源码走读. 拟牛顿法 数学原理 代码实现 L-BFGS算法中使 ...
- Apache Spark源码走读之16 -- spark repl实现详解
欢迎转载,转载请注明出处,徽沪一郎. 概要 之所以对spark shell的内部实现产生兴趣全部缘于好奇代码的编译加载过程,scala是需要编译才能执行的语言,但提供的scala repl可以实现代码 ...
- Apache Spark源码走读之13 -- hiveql on spark实现详解
欢迎转载,转载请注明出处,徽沪一郎 概要 在新近发布的spark 1.0中新加了sql的模块,更为引人注意的是对hive中的hiveql也提供了良好的支持,作为一个源码分析控,了解一下spark是如何 ...
- Apache Spark源码走读之7 -- Standalone部署方式分析
欢迎转载,转载请注明出处,徽沪一郎. 楔子 在Spark源码走读系列之2中曾经提到Spark能以Standalone的方式来运行cluster,但没有对Application的提交与具体运行流程做详细 ...
随机推荐
- strtol函数
今天做啦一个进制转换的题,改来改去最终倒是过啦,本来挺开心的,然后去翻啦一下题解,瞬间就有小情绪啦,哎,人家的代码辣么辣么短,实在是不开心,不过谁让咱是小渣渣呢,在此总结一下strtol 函数. 先来 ...
- 一张图看Google MVP设计架构
这段时间看了一下Google官方推出的MVP架构案例,决定把对MVP的理解用类图的形式表述一下.MVP架构的设计思想确实非常值得学习,大家如果还不是很了解MVP,建议抽时间去研究研究,相信对大家的架构 ...
- linux下DNS设置以及解析顺序
1.编辑/etc/resolv.conf文件,添加如下语句: nameserver dns_ip(例如nameserver 8.8.8.8) 2.如/etc/nsswitch.conf中未包含启用DN ...
- table extraction
http://yz.mit.edu/papers/webtables-vldb08.pdf http://www.vldb.org/pvldb/vol4/p528-venetis.pdf Alon H ...
- HDOJ1010(BFS)
//为什么bfs不行呢,想不通 #include<cstdio>#include<cstring>#include<queue>using namespace st ...
- poj2503 哈希
这题目主要是难在字符串处理这块. #include <stdio.h> #include <string.h> #include <stdlib.h> #defin ...
- 地球坐标系与投影方式的理解(关于北京54,西安80,WGS84;高斯,兰勃特,墨卡托投影)
一.地球模型 地球是一个近似椭球体,测绘时用椭球模型逼近,这个模型叫做参考椭球,如下图: 赤道是一个半径为a的近似圆,任一圈经线是一个半径为b的近似圆.a称为椭球的长轴半径,b称为椭球的短轴半径. a ...
- CSS3实现轮播图效果2
先前用CSS3做了一个一张图片实现的轮播,但是这样的图片很难找,于是又改进了一下. HTML: <div class="box"> <ul> <li& ...
- Jquery动画效果--地铁站名指示等效果
源码参考:源码爱好者--jQuery仿地铁线路指示灯效果,经修改和美化,特此记录一下. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tra ...
- 如何解除改变phpmyadmin数据库导入文件大小限制?
1.进到自己的系统里面 打开php.ini的配置文件 修改php.ini: file_uploads on 是否允许通过HTTP上传文件的开关.默认为ON即是开 upload_tmp_d ...