Prism4.0ctp prism application architecture)

Source: Internet
Author: User

Http://archive.cnblogs.com/a/1818452/

Author: huhahacn Source: blog Park Release Date: Read: 843 Original article links [favorites]

Prism allows you to select any part of it for use. You can choose to use any combination of Model-View-viewmodel (mvvm) mode, modularity, regions, commands, or events. However, if you are dedicated to low coupling and want to get all the benefits of prism, you can design your UI by referring to a standard architecture.Program. This architecture helps you organize your solutions. In addition, you can enjoy more abstraction and patterns than just using the prism library features, these can be applied to your program.

 

Solution folder structure

A typical PRISM program has multiple engineering projects. Includes the main UI application project, a Silverlight application project, or a WPF application project. It is called an appearance program or appearance project. When you use the prism module features, it also contains the appearance. You also have one or more module projects. In addition, a typical project contains one or more public class library projects, which are shared by the appearance project and module project. Demonstrate the organizational structure of the stock trader reference implementation (stock trader RI) solution. The stock trader Ri consists of two platforms: WPF (desktop) and Silverlight. In the figure, the folder of the WPF desktop application is not displayed. For more information, see the folder structure (stocktraderi. silverlight, including four module projects (marketing, news, jobs and observations) and a public class library project (stocktraderri. infrastructure. silverlight ).

 

Organization structure of the folder of the stock trader Ri Solution

 

 

Prism class library

In addition, most projects need to apply the prism class library assembly. The prism class library contains three sets. You can reference the compiled DLL or add the source code project to your solution and reference the project. The advantage of the latter is that you can view the prism source code type through the Goto method and perform a strong name signature on the prism class library assembly as part of your project.

 

Bootstrapper)

Bootstrapper corresponds to the initialization process of building an application using prism. Through bootstrapper, You can initialize some of your programs in a centralized manner.CodeYou can also better control the prism class library components to connect to your applications. For example, if you want to add a prism class library to an existing program, you can initialize the bootstrapping process after the program runs ).

In traditional WPF programs. specify the Uniform Resource Identifier (URI) method in the XAML file to start the main form. In traditional Silverlight programs. XAML. set rootvisual in the code behind file of CS. Programs created using the prism class library start the appearance or main form through the duties of bootstrapper. This is because the startup of the appearance depends on some prism services, such as the region manager and time aggregator, which need to be registered before the appearance display.

The prism class library contains two abstract bootstrapper classes. unitybootstrapper is used for the overall container (Unity container), and mefbootstrapper is used for the MEF (managed extensibility framework) to process the initialization process. Many methods in the unitybootstrapper class are virtual methods. You can reload these virtual methods inherited from the base class to implement your custom bootstrapper. If the container you use is not unity, you can write a bootstrapper for this special container.

Bootstrapper implements a workflow to initialize the PRISM program. Includes creating and initializing containers, Region adapter ing region adapter mappings, appearances, and modules. Displays several stages of bootstrapper startup.

 

Start the Boot Process

Container)

The dependency injection container is used to resolve dependencies between components. Resolving dependencies usually makes the container aware of the types and instances, and is used to resolve dependencies (registration ), obtaining these references depends on a consumer (resolution ). The prism Class Library supports managed extensibility framework and (MEF) and unity Application Block (Unity) containers, but it is not a specific container. Because the class library accesses the container through the iservicelocator interface. The container can be replaced. To use another container, you only need to implement the iservicelocator interface and expose your container API to register and resolution. In addition, if you want to change the container, you must implement your own specific bootstrapper. The iservicelocator interface is defined in the common service locator class library. This is an open-source achievement that implements IOC (inversion of control) Abstract containers, such as dependency injection containers and service locators. The purpose of using this class library is to collaborate with IOC and service locator.

The prism Class Library provides mefservicelocatoradapter and unityservicelocatoradapter. Mefbootstrapper class and unitybootstrapper class register their respective implementation based on iservicelocator. When dependency injection is required, the required container is used as long as the prism class library code is used, this ensures that the prism class library is decoupled from the container used.

For self-developed code, you can simply develop code based on the APIs of your container. You don't have to abstract it through iservicelocator unless you want your code to be unknown to the container. For example, the prism reference guide and reference implementation demonstrate APIs that are not directly implemented based on MEF and unity containers.

 

Appearance (Shell)

The appearance refers to the main form or root UI element of the application. The main form includes UI-related content. When necessary, the application appearance can be composed of multiple forms, but in most cases, there is only one form that contains multiple views. In the Silverlight application, the rootvisual element is considered. The appearance may contain elements called region. Multiple View elements can be presented in the area. The appearance can also be composed of a top-level UI element, such as a main menu and a work bar. The appearance shell defines the overall visual style of the entire application. The styles and borders can be displayed in the appearance shell layout. You can also define styles, templates, and themes, and then apply them to the view and insert them into the appearance shell.

In a prism application, the appearance shell does not need to understand the functions of the application. It only provides content display, so it is called "appearance shell ".

 

Module

The module is a functional unit in a prism application. Properly designed modules can be decoupled from the entire application and other modules. By splitting an application into modules, you can improve your isolation module skills, install different feature sets, deliver applications of different versions, and add new modules to expand your application functions.

The module-defined method allows you to discover and load modules when the application is running. A module can communicate with other modules or access services in a loosely coupled manner. This method reduces conflicts during maintenance, addition, or removal of system functions. The module design can also help with testing and deployment.

The common usage of a module is to represent different functional sets. For example:

    • The module contains a specific program function, such as the news function.
    • A module contains a specific subsystem, such as a purchase, payment, or checkout system.
    • The module contains basic services, such as log and authorization services or web services.
    • The module includes services that call the line-of-business (LOB) system, such as Siebel CRM and SAP, to supplement the internal system.

The following example shows four modules in stock trader Ri:

    • Position. This module is used to display positions and process purchase/sale orders.
    • Market. This module is used to process statistics and trend information of real investment portfolios.
    • Observe. This module processes the observed list, which is used to display the list of funds that interest users. At the same time, the list content is added and deleted.
    • News. This module is used for news gathering and display related to user investment.

When you develop your program in a modular manner, you should divide the program into independent modules for development, testing, and deployment by different teams.

 

 

Views and view models views and viewmodels

Views is a part of the UI that contains the appearance form. You can view it as a user control displayed on the client. In fact, the prism class library does not have to be defined as a user control. You can use a data template to define a view to present model data. Views can be displayed freely through the WPF capability. Simply put, view is a set of UI elements that define the UI rendering part. It provides an encapsulation form for each independent part of your UI.

Model-View-viewmodel (mvvm) mode has become the most common mode in the WPF/Silverlight display mode. When the mvvm mode is used, the view is associated with the view model at runtime and provides data and interaction logic to support the display of the view.

 

Controller Controllers

Another important role of your program code is to manage views. You need to control the logic to create and initialize the view instance, and then display it in the appearance shell, or combine the view and switch the view when appropriate. The logic of switching and displaying views driven by user interaction actions may also include the logic that occurs in the background. The application controller Pattern Defines the image of such criticism. In the Quick Guide and the stock trader Ri example, you can see the Controller controller example and the Controller controller implementation.

 

Services

In the context of a composite application, a service refers to a set of common functions that can be accessed through the service locator pattern of the service locator. Simply put, it only provides some functional classes in your application. In fact, do not construct a class instance by yourself. You need to use the service locator mode to obtain the reference of the class instance. Typically, you need to obtain an interface reference instead of a specific type reference, so that the consumer code can be decoupled from the specific type of the implemented interface. After obtaining the reference, you can use the Service to use the corresponding functions.

The following is an example of several services:

    • Basic Service: infrastructure services. Region manager region manager and event aggregator are examples of basic services. They provide disruptive support for communication between applications and components. Other basic services you need to write may include a cache service or an authorization and authentication service.
    • Data Services. In general, a service is used as a facade, represented in the relationship between your view model view models and the Controller controllers and the data source. Then go to the presentation layer. Data may be directly obtained from a disk, database, or a Web service. Data Service avoids the coupling between the display logic and the data logic to be displayed.

Generally, a service in the context is a service in a process. It may also be a package call of an out-of-process service and then serves as a web service. However, it may also be an object in the memory space as a client, so that it can be decoupled through the service interface and service locator mode.

 

Summary

A typical prism application coordinates each independent part through the concept of atomicity. Demonstrate this sample application architecture.

 

Sample prism application architecture

 

In this example, the app creates a boot starter bootstrapper and starts it. Bootstrap initiator bootstrapper creates and presents the shell appearance. Module A loads and injects three views into the appearance shell. Each view has a view model in the background. The first two views may be displayed in the region. The controller obtains data from the service to create and initialize them. In the third view, it is displayed only once and does not need to be changed, so the controller is not included, but it still supports the view model, the view model manages its own data through services. The module class, view model, controller, and service objects not described in the figure are all created through the container, so that all dependencies can be injected into the container.

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.