Build an ASP_NET Logic Piece Library
summary
Develop high-rejection, loosely coupled, framework, use ASP.NET, well-formed web applications. And you can form a highly available component library.
Object
This article is mainly for developers, project managers, and leaders responsible for software quality using ASP.NET development BS systems.
Background and solution
Background, application software features: 1. Various business, complicated business, customers uniquely require a lot, many versions, some companies have a new version to each customer, very few people know the difference between all versions, so Many versions have become the company's heavy burden, 2, product function coupling, difficult function is difficult to reuse, 3, software modification tasks are heavy, maybe this is the most painful, one project has been developed, and customers continue to make changes Many developers have long fallen into the modified task. These features and problems make the company's development department like a snowball, the greater the work, and the workload is getting heavier.
Solve the way:
For the above issues, application software development can solve the problem using the following method:
1. Extract the component and improve reuse.
2, interfacial skin, easy to modify, the interface has changed.
3, script parameters to avoid coupling.
content
Framework: including the page, component library, data component library, and data component factories. The page is responsible for the overall appearance of the website and loads the component library, the component library provides logic functions, the data component library provides business data, and the data component factory is responsible for generating data objects. These four parts can be summarized as two ties of two libraries. The page is the tie of component libraries and users, and the data component factory is the link between component libraries and data components.
1, page
The page is responsible for the overall appearance of the website and loads the component library.
The page is the performance of the website's overall UI. The main work is the picture production, page cutting, loading components, and transmitting parameters to the component, and to be responsible for website navigation.
Division: Artists and skilled people developed.
2, component library
This is the core of the framework. We use the User Control to complete this 3 points:
1. Extract the component and improve reuse.
2, interfacial skin, easy to modify, the interface has changed.
3, script parameters to avoid coupling.
1. Extract components and improve reuse.
Package the processing part of a logical function into user controls, which is easy, mainly how to reuse, usually we mainly use user controls in the same project, but only cross-engineering can be reused, in fact, CodebiHand technology is one Inheritance relationship, the user interface inherits the self-class library, so reference the class library where the user control is located to the project, and put the user control ASCX code into the project's directory, you can use the user control in the same project. .
Also, if you need to debug, you can place the source code into the directory where the user control is located, you can track debugging.
2. Interface skin, easy to modify, the interface is changeable. The interface of the user control is easy to modify. This also deeply understands CodebiHand technology, multiple ASCX files (control UI code) can correspond to the same CS file (control class code). We also need to do this, for example:
This is a login component, the function is to accept user input, verify the user, return login information, if successful, and guide other pages. After this component is completed, we find that there is also a login component that can be placed on the navigation bar. This is three options, 1, create a new, copy code, code multiplex, but code repeat brought quite Trouble. 2, expand component function, how to display it through a parameter. This has a problem. To modify the program, it is a program to become complex, and the use of code control shows is often troublesome in the future maintenance stage. It will need to modify the program, 3, make a suede, the programmer is easy, the code does not change And the skin can be convenient to modify, and it is easy to maintain. This is the landing component on the navigation bar.
Let these 2 UI part correspond to the same CS code, it is a good idea.
In the Microsoft Visual Studio .Net 2003 development tool, it is not very good to support this, it does not have a good form of organizational form of this code, and it seems that the CS code of one of the controls seems to be lost. Figure:
GCON_LINELLOGIN.ASCX's code is not related to it, but does not affect the use.
It may be that Microsoft did not think of it, but we really need this, and get benefits.
Division: Software Engineers can be detailed, functional division, and developing components, may not be very beautiful, then, the beauty can take the skin of the component to make multiple sets of different skin components. There is only one encoding of the components, so that the diversification of the component is realized, and the generation of multiple versions is avoided.
3, script parameters to avoid coupling.
The use of controls will inevitably involve interaction with other controls and pages. For most user controls, it is not very complicated with the interaction of the page and other user controls, such as the above login control, just need to know the successful login, to display that page, to use script delivery parameters for this simple interaction It is written in the page without using Codebihand technology. The code written on the page is more likely to change, which reduces strong coupling.
Let's take a look at how to write script code:
Through analysis, the discovery page part and the Codebihand code are the relationship between inheritance. So we can overload the oninit () method. The implementation of the page is to join us. In this way, the parameters are transmitted, and the value of this parameter is changed at any time, and the program does not need to be compiled.
Error approach, directly decide which page of the user control, does not leave parameters, this user control will completely lose flexibility because of this small move, and lose the possibility of reuse.
Additional:
The use of user components,
The ASP.NET user component is very large, and the user component is first a server component, which has the advantages of the server side, and is convenient to development, and it is very suitable for application developers.
If you want to use the user component, you need to know the following:
1. In-depth understanding of CodeBehind, which is not only developed like developing Win Form programs.
2. Try to add attributes, events, methods to user components. Fully expand and understand the function of the user component.
3. Try to let the user component inherit a custom interface, the interface is very powerful, we have to use it.
4, dynamically load the user member. Multiple user components on the same page can be all dynamically loaded.
5, load the user component in another DLL, which can be reused from the user component to build the basis of our own component library. 6, let the art give a compiled user space to make different skin (edit the HTML code in ASCX), you can find that because the ASCX code changes, the user component will have a variety of faces to form a variety of interfaces. series.
7. Do not pass parameters to the user component by changing the CS code of the page, so that the loose coupling of the component and the page can be achieved, the page is added, reducing the components, transmitting parameters, and unchartable procedures.
to sum up:
Using C # development business components and component plants, this is not written here. The ASP.NET component library and business architects cooperate together to unify high quality development processes, including the division of labor and programmers, forming a professional material library, etc. The resources of the company.
Author: Wang Lusheng
QQ: 44079546
Email: Wanglusheng1@163.net
Peking University Software Engineering Co., Ltd. Software Development Engineer.
2004-06-05