《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的提交与具体运行流程做详细 ...
随机推荐
- svn上传文件
转自:http://zhouhaitao.iteye.com/blog/1122918 如何将指定文件或文件夹直接提交到svn指定目录? 如何将指定文件或文件夹直接提交到svn指定目录? 一般我们都是 ...
- Flex4 自定义分页组件
自己写的Flex4分页组件,去伪存真,只实现基本的分页功能,数据过滤神马的都不应该是分页组件干的活,有呆毛才有真相: [源代码下载] Flex自从转手给Apache后人气急跌,本人也很捉鸡,尽管Apa ...
- Add, remove, shuffle and sort
To deal cards, we would like a method that removes a card from the deck and returns it. The list met ...
- Hibernate 常见异常
Hibernate 常见异常net.sf.hibernate.MappingException 当出现net.sf.hibernate.MappingException: Error r ...
- 互联网+医疗(FW)
http://www.yn.xinhuanet.com/health/2015-06/05/c_134300133.htm 互联网+医疗 让合适的病人找合适的医生 www.yn.xinhuanet.c ...
- Android基础总结(1)
1.Android开发的特点 四大组件:活动(Activity).服务(Service).广播接收器(Broadcast Receiver).内容提供器(Content Provider).其中活动是 ...
- IBM Tivoli NetView网管软件实战
广大网络管理者需要一款包括网络监控故障处理的一个集成网络管理平台,本文根据作者多年实践提出的基于IBM Tivoli Netview的综合网络管理平台,IBM Tivoli与Cisco一直保持着良好的 ...
- Windbg + .Net .NET Memory Profiler 排查内存泄露
这是一个Winform程序,用于项目中的定时运算.症状是,运行一段时间后,内存持续上升.如一天内就能够达到300M. 打开.Net Memory Profiler,监控该程序,一段时间后,看到该程序产 ...
- 委托delegate使用方法
允许传递一个类A的方法m给另一个类B的对象,使得类B的对象能够调用这个方法m,说白了就是可以把方法当作参数传递. class Program { //delegate的使用方法一 public del ...
- pcap文件格式及文件解析
第一部分:PCAP包文件格式 一 基本格式: 文件头 数据包头数据报数据包头数据报...... 二.文件头: 文件头结构体 sturct pcap_file_header { DWORD ...