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();
}

  

最新文章

  1. 身份证验证JS代码
  2. Ruby中 Include, Extend, Import, Require 的使用区别
  3. JDBC查询数据库中的数据
  4. vs2015 使用 visual studio on line 在线版本控制
  5. Android开发-开发前的配置
  6. ```````````````辐射度 Radiometry
  7. poj 1924 Paths on a Grid(组合数学)
  8. python用paramiko将执行的结果存入excel表格
  9. Dolls - 4160(简单二分图匹配)
  10. .Net Web开发中实现剪切板功能
  11. VIM 多行输入 数字递增 新方法 循环记录法
  12. unslider插件的使用
  13. 将DLL文件直接封装进exe执行文件中(C#)
  14. Android View框架总结(四)View布局流程之Measure
  15. 【翻译】Ext JS——高效的编码风格指南
  16. 记 Win10 + Ubuntu18.04 安装
  17. Juploader 1.0 谷歌(chrome)浏览器中成功上传文件后返回信息异常
  18. Unity3D鼠标坐标转世界坐标和局部坐标
  19. 如何使用C语言的面向对象
  20. jenkins借助winscp传本地文件到远程服务器上

热门文章

  1. cocos2d-x 中 TTF 字体文件的位置
  2. Appium小试
  3. 联系博主(推介联系QQ)
  4. python写的battle ship小游戏 - 1.0
  5. 使用eclipse上传项目到开源中国代码托管Git@osc教程
  6. 了解Entity Framework中事务处理
  7. 关于ORA-04021解决办法(timeout occurred while waiting to lock object)
  8. org.springframework.jdbc.BadSqlGrammarException
  9. Andriod项目开发实战(1)——如何在Eclipse中的一个包下建新包
  10. 操作笔记:linux下查看端口被占用