"Prism 5.0 source of the daytime" Unitybootstrapper

Source: Internet
Author: User

Unitybootstrapper (abstract Class) inherits from the bootstrapper (abstract) class in Prism.UnityExtensions.Desktop project. The main purpose is to support unity Container (Dependency injection Container).

Open Unityboostrapper Source code we can see that the following logic is mainly in this area:

1. Defining Unity Container Properties

 Public Get protected set; }

2. Override the Run () method

 Public Override void Run (bool  runwithdefaultconfiguration) {         ...  }

This is the entrance method of bootstrapper, and it is also the entrance method of the whole application. The logic of application initialization is primarily called in the Run () method.

  • Create a logger instance (Bootstrapper implementation, virtual method)
     This this. Createlogger ();
  • Create a Modulecatalog instance (Bootstrapper implementation, virtual method)
     This this. Createmodulecatalog ();
  • Configuring Modulecatalog instances (Bootstrapper implementation, virtual method)
    this. Configuremodulecatalog ();
  • Create a DI container instance (Unitybootstrapper implementation, virtual method)
     This this. CreateContainer ();
  • Configuring Di Container (Unitybootstrapper implementation, virtual method)
    this. Configurecontainer ();
  • Configure Servicelocator (Unitybootstrapper override bootstrapper abstract method)
    protected Override void Configureservicelocator () {      this. Container.resolve<iservicelocator>());}
  • With the mapping of region adapter, there are mainly three Mapping:selector,itemscontrol,contentcontrol (bootstrapper implementations of region adapter, Virtual method)
    this. Configureregionadaptermappings ();
  • Configure the default region behaviors (Bootstrapper implementation, Virtaul method. ) Mainly include: Bindregioncontexttodependencyobjectbehavior,regionactiveawarebehavior,syncregioncontextwithhostbehavior, ETC., Refer to Boostrapper Configuredefaultregionbehaviors method in detail.
    this. Configuredefaultregionbehaviors ();
  • Registering the exception type of the PRISM framework throw out (overriding the Boostrapper method)
    protected Override void registerframeworkexceptiontypes () {     base. Registerframeworkexceptiontypes ();     Exceptionextensions.registerframeworkexceptiontype (     typeof( Microsoft.Practices.Unity.ResolutionFailedException));}
  • Create the application shell (called the abstract method defined by the Boostrapper), which you need to implement when using prism.
     This this. Createshell ();
  • If the shell is created successfully, the Setregionmanager and Updateregions methods in Regionmanager are called to handle the association of the region. The initialization shell method of the parent class (virtual, no specific implementation) is called later.
     if  (this . Shell! = null  ) { this  .    Logger.Log (Resources.settingtheregionmanager, Category.debug, Priority.low); Regionmanager.setregionmanager ( this . Shell, this .    Container.resolve<iregionmanager> ());  this   this   this   
  • Initialize the modules, overriding the parent class method
if (this.) Container.isregistered<imodulemanager>()) {    this. Logger.Log (Resources.initializingmodules, Category.debug, Priority.low);      This . Initializemodules ();}

At this point, the Run () method is complete.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.