Document directory
- I. Framework Introduction
- Ii. Functions of the Spring framework
Start from this article to learn about spring.. NET Framework, for many programmers, spring. the Net Framework is contradictory. You must configure files that have not been exposed before, and more programmers do not know about spring. NET framework. This chapter mainly introduces spring. net Framework introduction and module description.
I. Framework Introduction
The Spring framework is very elegant. Thanks to the integration of its advanced architecture series along with ideas, it is very popular when it comes to production. The design model is a perfect place, And the elegant charm has conquered Xu Java and made them a believer, it is a good programmer, and spring leads the J2EE trend. At the same time, various spring frameworks have joined forces with believers to fly as soon as possible, such as the old brother SSH (configuration cumbersome strutshib.pdf, spring integration) qixiu ejsa (lightweight, flexible, and zero-configuration easyjweb + JPA + spring + acegi, suitable for efficiency-oriented Enterprises) is becoming mature with spring, bringing endless convenience.
So can the. NET users enjoy the spring meal? The answer is yes. The spring team should transplant the idea of the plupring framework and contribute the spring. NET framework suitable for the. NET project. There are few articles on spring. NET and no documents on spring.net are searched for in Baidu.
First of all, let's get to know spring. net. In short, spring. net uses a variety of strong design patterns for tool management. Spring. NET provides a well-tested design model that enables scientific and rational management and integration at all levels of the enterprise level and distributed groups. It also coordinates relations between enterprises and enhances project robustness.
The spring. Net IOC container solves the issue of merging the enterprise application class and Image Service Group applications. IOC containers distribute groups to form a complete application program by means of unified (by: formalized, which has been finalized and tested by the industry. Spring. the Net Framework has been tested by countless application programs in the industry for years and has been finalized to design the best programming methods. In reality, these models have become the Framework Code and passed spring. to integrate their own applications. Currently, the Spring framework of an organization is robust and well maintained, which is indeed very good.
Description of the spring. NET Framework module:
{
Function onclick ()
{
Get_larger (this)
}
} "Src =" http://img.kanwenzhang.com/images/t2/200907/20090705222804635.jpg "border =" 0 "alt =" spring.net (<a href = ">
1. Spring. Core serves as the basis of the entire framework to implement the dependency injection function.
Some modules of spring. Net depend on or expand this module. Spring. core basic iobjectfactory interface, which implements the factory mode in a simple and elegant way, so that you do not need to compile the singleton Type Public Service positioner, and perform logical decoupling like configuration and dependency. The iapplicationcontext interface of this module is extended to iobjectfactory. Various enterprise-level functions are added, including the localization of resource text and loading of event propagation resources.
2. The spring. AOP business image provides support for Aspect-oriented programming (AOP.
AOP improves IOC container functions, and enterprises should lay a solid foundation for declarative services.
3. Spring. webasp. Net series feature extensions, including ASP. NET page dependency injection, bidirectional data binding, ASP. NET 1.1 master page, and enhanced Localization support.
4. Spring. Services any "normal" image (meaning that it does not inherit any specified base type image) to publish an Enterprise Service (COM +) or remote image.
This module provides the. netweb service with great flexibility through dependency injection features such as metadata coverage. Windows Services are also supported.
5. Spring. Data defines an abstract data access layer to access data across various data access technologies (from various orm of ADO. net.
This module contains an ADO. Net abstraction layer to reduce the workload for traditional ADO. Net coding transaction management.
6. The popular ORM class library in spring. Orm provides an integration layer, which includes declarative transaction management and other functions.
Through the above introduction, we will roughly discuss spring. net Framework has a rough understanding, as to how to introduce spring in project development. NET framework and how to use spring..
Ii. Functions of the Spring framework
No spring is found yet. the role and power of net, and spring introduction articles on J2EE are quite common. I have reposted an article about Spring function, which involves a lot of content, however, it briefly explains the role and usage of the Spring framework. [Note the following code is Java code, which only describes spring]
Application Background: There is an application that requires good access to USB flash drives or mobile hard drives (if the read and write algorithms of the two media are different). If you are a developer, how should I develop this application?
• Note: The program has only two functions: readinfo () and writeinfo ()
• Solution 1: Develop all possible media algorithms in the application. But this method is not good. You need to modify the code every time.
• Solution 2: Use spring for management
As follows:
1. Define a USB flash drive:
// Define the USB flash drive class </P> <p> package USB disk; <br/> Import app. idisk; </P> <p> public class usbdisk implements idisk {</P> <p> Public String readinfo () {</P> <p> return "Information read from the USB flash disk"; </P> <p >}</P> <p> Public void writeinfo (string MSG) {</P> <p> system. out. println ("write information to the USB flash drive:" + MSG); </P> <p >}< br/>
2. Define mobile hard disk categories:
Package movedisk; </P> <p> Import app. idisk; </P> <p> public class movedisk implements idisk {</P> <p> Public String readinfo () {</P> <p> return "Information read from mobile hard disk "; </P> <p >}</P> <p> Public void writeinfo (string MSG) {</P> <p> system. out. println ("write information to a mobile hard disk:" + MSG); </P> <p >}</P> <p>
3. Define an interface to manage USB disks and mobile disks:
Package app; </P> <p> Public interface idisk {</P> <p> public abstract string readinfo (); </P> <p> public abstract void writeinfo (string MSG); </P> <p >}< br/>
4. Compile the configuration file:
<? XML version = "1.0" encoding = "UTF-8"?> </P> <p> <! Doctype beans public "-// spring // DTD bean // en" "http://www.springframework.org/dtd/spring-beans.dtd"> </P> <p> <beans> </P> <p> <! -- Object generation is completed by the framework through the reflection mechanism, and control is transformed from the front-end main program to the Framework. </P> <p> this idea is called control inversion (IOC ), inverse of control, which can implement module switching well --> </P> <p> <bean id = "disk" class = "usbdisk. usbdisk "> </bean> </P> <p> </beans>
5. Compile the test code:
Package app; </P> <p> Import Org. springframework. context. applicationcontext; </P> <p> Import Org. springframework. context. support. filesystemxmlapplicationcontext; </P> <p> public class mainmodule {</P> <p> Public static void main (string [] ARGs) {</P> <p> // read the configuration file </P> <p> applicationcontext context = new filesystemxmlapplicationcontext ("applicationcontext. XML "); </P> <p> idisk disk = (idisk) context. getbean ("disk"); // instantiate the object based on the content of the configuration file and return </P> <p> disk. writeinfo ("hello"); </P> <p >}</P> <p>}
We can see that this disk refers to USB disk. USB disk refers to a USB flash disk. If you want to change it to a mobile disk, you only need to modify <bean id = "disk" class = "movedisk. the value of movedisk "> </bean> class is enough.
The caller (application) and module (USB flash drive or mobile hard drive) are linked with the configuration file.
When a USB flash drive or mobile hard disk is connected, the configuration file is changed, and the caller is always reading the configuration file without changing the source code.
If the configuration file is changed, you can switch the module or even change the module behavior.
The test code is only intended for interface programming, without the need to know the specific name of the implementation class. At the same time, we can easily change the configuration file to switch the specific underlying implementation class.
• Spring role 1: this idea can well implement switching between modules of the same type and different qualities: for example, you need to write content to different media components in different ways to reduce dependencies. In the above example, we use spring to dynamically inject strings into the attributes of the implementation class at runtime. This concept transfers parameters to the container for dependency injection.
• Spring Function 2: You can easily change module behavior through the configuration file and dynamically inject attribute values.
It can be seen that spring can better help us achieve code separation.