Analysis of the hybrid framework of Winform development framework-Implementation of the hybrid framework of Winform development framework evolution of Winform development framework

Source: Internet
Author: User
Document directory
  • 1. Fan out of the framework
  • 2. Integration of auxiliary modules of hybrid frameworks
  • 3. Separation of projects and configurations of hybrid frameworks
  • 4. Introduction to calling hybrid frameworks
  • 5. Support for mixed framework code generation tools
  • 6. Summary of mixed framework Optimization

I introduced the variants and hybrid frameworks of the Winform framework in both the evolution of the Winform development framework and the implementation of the Winform development framework, this article further describes the hybrid framework.

1. Fan out of the framework

In order to support two data operations: the WCF method and the traditional database access method, the hybrid framework has two fan-out operations, one is fan-out operations when you call an interface object to obtain data. The following shows how to process data in the WCF and traditional database access methods. Of course, if necessary, it can also be extended to support more types, such as WebService calling methods in the old system.

In addition, the entire framework supports Access to Oracle, SqlServer, MySql, Sqlite, Access, and other databases. Therefore, when the business layer calls a specific data category, it depends on the configuration, the database access objects are also different. Therefore, there is also a fan-out operation, and the number of fan-out operations is consistent with the supported database, as shown below.

2. Integration of auxiliary modules of hybrid frameworks

The hybrid framework can be regarded as an advanced version of the Winform framework. Apart from being a complete business system, all auxiliary modules on its periphery (such as general permission, general dictionary, general attachment management, general personnel management ....) This hybrid framework is implemented, so it is very convenient to use. If the whole framework is simplified, it is the original Winform interface layer that uses the interface call method, avoid tight coupling with the business logic class. Because it is called through an interface, it can be configured to point to the implementation of WCF, so it also covers all the features of the WCF framework.

3. Separation of projects and configurations of hybrid frameworks

Speaking of the access method of WCF, the hybrid framework separates the WCF Service of the Business System from the WCF Service of the auxiliary public module. First, the service is separated, and then the client configuration files are separated.

The client configuration files are separated by using different files for their service configuration information. For example, the WCF configuration file of the auxiliary module is BaseWcfConfig. config. The business system's WCF configuration file is WcfConfig. config. With this separation setting, we can use the main configuration file app. in the Config file, there is a lot of refreshing, as shown below.

<Deleetask> <! -- Software name --> <add key = "ApplicationName" value = "Shen Tian star Warehouse Management System"/> <! -- Developer name --> <add key = "Manufacturer" value = ""/> <! -- Component Database Type: access, sqlserver, sqlite, oracle, etc, the default value is sqlserver. Do not write --> <add key = "ComponentDbType" value = "sqlserver"/> <add key = "AttachmentLicense" value = "allow"/> <! -- Component module call method. The Value in WCF mode is wcf, and the Value in Winform mode is win --> <add key = "CallerType" value = "wcf"/> <! -- Configuration file address of the WCF Service --> <add key = "BaseWcfConfig" value = "BaseWcfConfig. config "/> <add key =" WcfConfig "value =" WcfConfig. config "/> </appSettings>

In this way, we modifyCallerTypeTo achieve two different access methods.

The layout of the entire project, in addition to the WCF Service Module just introduced, actually there are many other modules, as shown in the figure below, including the business logic module and service interface call module, the Winform interface module and the WCF Service logic module include the entire system module. Of course, the peripheral auxiliary modules, such as dictionaries, permissions, and personnel, are organized and processed in this way, when the system calls them, it does not care about their calling logic, because their calling methods have passed the agreedCallerType.

4. Introduction to calling hybrid frameworks

For a hybrid framework, no matter whether its data calling logic adopts the traditional Winform method or the distributed WCF Service calling method, the implementation code is the same, because it is called Based on the interface layer, the following shows how to call the data dictionary module to obtain data in the framework system.

/// <Summary> /// obtain the corresponding CListItem set based on the dictionary type /// </summary> /// <param name = "dictTypeName"> </param>/ // <returns> </returns> public static CListItem [] GetDictByDictType (string dictTypeName) {List <CListItem> itemList = new List <CListItem> (); Dictionary <string, string> dict = WHC. dictionary. UI. callerFactory <WHC. dictionary. facade. IDictDataService>. instance. getDictByDictType (dictTypeName); foreach (string key in dict. keys) {itemList. add (new CListItem (key, dict [key]);} return itemList. toArray ();}

The System Framework calls its own interface to obtain data, and the mode is the same as above. Compared with the traditional Winform framework calling code, no workflow is added, but the calling object is a little changed.

Private void winGridViewPager1_OnDeleteSelected (object sender, EventArgs e) {if (MessageDxUtil. ShowYesNoAndTips ("are you sure you want to delete the selected record? ") = DialogResult. no) {return;} int [] rowSelected = this. winGridViewPager1.GridView1. getSelectedRows (); foreach (int iRow in rowSelected) {string ID = this. winGridViewPager1.GridView1. getRowCellDisplayText (iRow, "ID"); CallerFactory <IItemDetailService>. instance. delete (ID) ;}binddata ();}

If it is a traditional Winform framework, the core call code of its delete operations is as follows. Is it very similar?

BLLFactory<ItemDetail>.Instance.Delete(ID);
5. Support for mixed framework code generation tools

Of course, although the hybrid framework is more common than the traditional Winform framework and the WCF development framework, it introduces multiple layers and achieves separation of more modules, it adds some design complexity, and the entire project looks a little more complicated. For example, the following is the internal structure of a hybrid framework that uses the dictionary module as an example.

To achieve simpler development and more efficient development of the hybrid framework, I expanded my code generation tool Database2Sharp to support code generation of this hybrid framework, in this way, developing a hybrid framework is just as convenient as developing two other Winform development frameworks and WCF development frameworks.

To generate a hybrid framework project, check the setting at the last step of EnterpriseLibrary code generation.

The Code Generation Tool generates a comprehensive hybrid framework project as follows, but there is no interface part. This part can be integrated with my hybrid framework case in the actual development process, in addition, you can also use Database2Sharp to develop the Winform interface, so that the integrity is very convenient:

6. Summary of mixed framework Optimization

Although the overall hybrid framework is more difficult and complex than the other two framework modules, in order to make the development and use of the entire hybrid framework more convenient, I have already done a lot of related work in the design, and strive to better and more efficiently use this hybrid framework. below is my optimization and improvement work on the overall framework.

1) develop all common modules to facilitate better integrated use, make more efficient use of common modules, and make more reuse;

2) Separate the release and service logic of the WCF Service to better manage and publish the WCF Service. The Service Release only requires the svc file and does not include any background code;

3) Unified Business Call rules and naming rules. Interfaces of all modules are called in the same way as CallerFactory <I *** Service>. The naming rules and mechanisms of common modules and frameworks are identical.

4) the WCF Service configuration file is separated. The configuration file of the universal auxiliary module is BaseWcfConfig. config. The business system's WCF configuration file is WcfConfig. config, configuration file separation is easier to manage and maintain, and the main configuration file app is reduced. the complexity of Config.

5) the last and most important one is the synchronization support of the Code Generation Tool Database2Sharp. Use code generation tools to generate code and project projects of the entire mixed framework better and faster, and solve all the troubles with one click. On the Winform interface, use the code generation tool Database2Sharp to generate and then integrate it in the project.

 

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.