Spring.net series (1) download and install and helloworld

Source: Internet
Author: User

1. Download:

Spring.net Official Website: http://www.springframework.net/

Spring.net Latest Version: Spring. Net-1.2.0

Spring.net updated on:

Spring.net: http://dist.springframework.org/release/NET/Spring.NET-1.2.0.exe

Download API documentation: http://dist.springframework.org/release/NET/Spring.NET-1.2.0-net-2.0-api.zip

Download Reference Manual: http://www.springframework.net/docs/1.2.0/reference/pdf/spring-net-reference.pdf

 

Ii. Installation

Download the spring.net-1.2.0.exe file and install it as prompted.

After the installation is complete, find the \ doc \ schema \ directory under the installation directory and copy *. XSD to the schema directory of Visual Studio:

Vs2005: C: \ Program Files \ Microsoft Visual Studio 8 \ XML \ Schemas

Vs2008: C: \ Program Files \ Microsoft Visual Studio 9.0 \ XML \ Schemas

In this way, you can use Visual Studio to configure XMLCodePrompt.

Iii. helloworld

It cannot be vulgar. Start with helloworld!

1. Development Environment

Windows XP English version

Visual Studio 2008 (SP1) English version

To facilitate Google, my development environment is in English.

 

2. Create a console application project named helloworld.

3. Solution Explorer)

4. Main files

Spring. Core. dll: this is the core library file of spring.net, which must be referenced first.

Add reference, find the bin \ net \ 2.0 \ release \ spring. Core. dll file in the installation directory of spring.net, and add it.

App. config: the most basic configuration of spring.net is provided here.ProgramCallingContext. GetObjectMethod to load the configuration file.

App. config
<? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>
<Configsections>
<Sectiongroup name = "Spring">
<Section name = "context" type = "Spring. Context. Support. contexthandler, spring. Core"/>
</Sectiongroup>
</Configsections>
<Spring>
<Context>
<Resource uri = "Spring. xml. config"/>
</Context>
</Spring>
</Configuration>

Hello. CS: This is a hello implementation class.

Hello. CS
Class Hello
{
Private   String Helloword;

Public   String Helloword
{
Get   {Return This. Helloword ;}
Set   {This. Helloword=Value ;}
}
}

Program. CS: main program.

Program. CS
Class Program
{
Static   Void Main ( String [] ARGs)
{< br> iapplicationcontext context = contextregistry. getcontext ();
hello = (Hello) context. getObject ( " Hello " );
system. console. out. writeline (hello. helloword);
system. console. in. read ();
}
}

Spring. xml. config: InMain ProgramCall context. GetObject and pass in the "hello" parameter. The corresponding class is located here to create an instance and assign a value to the helloword attribute of the Instance according to the configuration.

Spring. xml. config
<? XML version = "1.0" encoding = "UTF-8" ?>
< Objects Xmlns = "Http://www.springframework.net" >
< Object ID = "Hello" Type = "Helloworld. Hello" >
< Property Name = "Helloword" Value = "Hello! Welcome to spring. Net word! " />
</ Object >
</ Objects >

 

OK. After writing, press <F5>. The screen is as follows:

OK! The demo is complete.

............

Wait. Don't go first. Don't you think there is anything wrong with it?

By the way, although the example is already quite simple, isn't it easier to program directly without spring.net? Directly write the following in the main program:

Simpler Method
Namespace helloworld
{
Class Program
{
Static void main (string [] ARGs)
{
// Iapplicationcontext context = contextregistry. getcontext ();

// Hello = (Hello) Context. GetObject ("hello ");
Hello = new Hello ();
Hello. helloword = "Hello! Welcome to spring. Net World! ";

System. Console. Out. writeline (hello. helloword );
System. Console. In. Read ();
}
}
}

In this way, no configuration files are needed, so what are the troubles?

This is the core idea of spring.net, IOC. It depends on the configuration in the file to determine the execution trend of the program.

Of course, we still need to have this line in the program:

Hello = (Hello) Context. GetObject ("hello ");

The Hello class is coupled here. In actual projects, it can be solved through interfaces or generics.CouplingIt, I will continue to sell bricks in the future series. ^ O ^!

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.