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.