Silverlight Project NOTE 2: First knowledge of Prism and IOC

Source: Internet
Author: User

The project uses the Prism framework, and some of its initial understandings are as follows:

I. Prism

Prism is an MVVM framework for WPF and Silverlight developed by the Microsoft patterns & practices team, with the benefit of modularity of functionality that effectively reduces program size and enhances scalability and maintainability.

Several key points of Prism:

(1) Starter Class Unitybootstrapper

When invoking the Bootstrapper.run method at the entrance of the Silverlight program, Prism automatically does some initialization work, including reading the module information table, creating the module class instance and initializing it (optionally loading mode OnDemand), and specifying the root view of the entire program in Creatshell Figure.

(2) Inherit the IModule interface and do the module initialization work.

The UnityContainer container is passed into the constructor (using the IOC container unity) to get the container object, and a large number of resolve methods of the UnityContainer object are needed to get the object associated with the specified object. That is, use the container object container directly to get the instance or method.

And then do some module-related initialization in initialize, such as listening to event messages, when loading this module, the interface needs to do some work and so on.

(3) UI Management Regionmanager

Prior to the initialization of the module when the interface needs to do some initialization work, using the prism framework, it is easy to do the UI control of the switch navigation.

In the initialization of the module will need to use the page to register, when the need to load the page can be loaded directly into the specified area.

That is, a page "Xxxmainview" is registered when the module is initialized, and when it hears the event loading the page, it can be loaded into the previously designed page area "page region".

(4) Event aggregation service Eventaggregator

Prism provides event aggregation service Eventaggregator, which is more convenient to use than delegate events, register events, and then publish subscriptions directly, which will be used extensively in communication between modules.

Two. IOC Container Unity

The IOC is inversion of contro control inversion, the control of the code to the system control, such as object creation, method calls to unity to control, unity Microsoft patterns& practices team in C # Implementation of the lightweight, Extensible Dependency Injection container, the benefit of this is to eliminate the direct dependencies between modules, oriented to the abstraction of even interface-oriented programming, convenient program extension maintenance.

Using UnityContainer's Container object, the M_container, Container in the diagram, after registering the relationship between the object and the object (Idataservice and Xxxdataservice), It is possible to parse the registered object through the container object at any place throughout the program, and then execute the property or method of the registered object.

This is another way to communicate between modules in addition to the event aggregation service Eventaggregator.

Three. Benefits of using PRISM and IOC

(1) Functional modularity, the system is divided into multiple independent modules, convenient for many people to develop together;

(2) Effectively reduce the size of the program, modular development and IOC, interface-oriented programming, module responsibilities, so that the module repeated reference class library situation greatly reduced, compiled programs smaller, for Silverlight this rich client, improve the loading speed.

(3) The level logic is more clear and easy to develop;

(4) Low coupling between modules, when the module is not updated, you can unload, do not need to recompile, greatly reduce the compilation time.

(5) Enhance the expansion of maintenance.

So the system has a certain degree of complexity, when non-demo or prototype system, the use of Prism and IOC will be a good choice.

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.