Basics of spring. NET environment setup (favorites and Learning)

Source: Internet
Author: User

Let's take a look at how to use spring. net.

I. Environment download and Installation
Download the spring.netframework Installation File (spring.net-1.3.0-rc1.exe) to spring's official website ). Currently, the latest spring. Net version is 1.3. Download and unzip the package.

The following files are frequently used in spring. NET Framework:
Common. Logging. dll (required)
Spring. Core. dll (required)
Spring. Data. dll
Spring. AOP. dll (optional)
Spring. Data. nhibernate21.dll
Spring. Web. dll
In future blogs, we will learn some examples of combining nhib.pdf with ASP. net mvc. You can download the respective framework installation files from the official website of Hibernate and the official website of ASP. NET.

In an XML-based factory, these object definitions are represented as one or more <Object> subnodes, and their parent nodes must be <objects> (: the xmlns element of the objects node is required. You must add different namespaces based on different applications for intelligent ide prompts (see spring. net Chinese manual ).

 

Object. xml
<Objects xmlns = "http://www.springframework.net"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "http://www.springframework.net
Http://www.springframework.net/xsd/spring-objects.xsd>
<Object ID = "" type = "">

</Object>
<Object ID = "." type = "">

</Object>


</Objects>

 

You can also find spring.. net. NET-1.3.0-RC1 \ doc \ schema, put the number inside. copy XSD to the Microsoft Visual Studio 9.0 \ XML \ schemas folder under the vs2008 installation directory.

If necessary, install the template spring. NET-1.3.0-RC1 \ Dev-support \ vs.net-2008 \ install-templates.bat for setting up the spring. Net Program

2. Create a spring. NET application
Create a new objects. xml file, and then reproduce the configuration template from the spring. Net manual.

 

Objects. xml
<? XML version = "1.0" encoding = "UTF-8"?>

<Objects xmlns = "http://www.springframework.net"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "http://www.springframework.net
Http://www.springframework.net/xsd/spring-objects.xsd>

<Object ID = "persondao" type = "firstspringnetapp. persondao, firstspringnetapp">

</Object>

</Objects>

 

Currently, I have found two ways to instantiate spring. net capacity:
1. Actual physical path
Iresource input = new filesystemresource (@ "D: \ objects. xml"); // actual physical path
Iobjectfactory factory = new xmlobjectfactory (input );

2. Search for configuration files in the Assembly

 

 

Code
String [] xmlfiles = new string []
{
"File: // objects. xml"
};
Iapplicationcontext context = new xmlapplicationcontext (xmlfiles );

Iobjectfactory factory = (iobjectfactory) context;
Console. Readline ();

 

At present, I usually use the latter (looking for configuration files under the Assembly), which is easier to maintain.
This method must meet the URI syntax.
File: // file name
Assembly: // Assembly name/namespace/file name

However, a better way is to add custom configuration nodes in the configuration file app. config or web. config.
Introduce the <objects xmlns = "http://www.springframework.net"/> namespace in the configuration file, otherwise the program will not be able to instantiate the spring. Net container.

 

App. config
<? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>

<Configsections>
<Sectiongroup name = "Spring">
<Section name = "context" type = "Spring. Context. Support. contexthandler, spring. Core"/>
<Section name = "objects" type = "Spring. Context. Support. defaultsectionhandler, spring. Core"/>
</Sectiongroup>
</Configsections>

<Spring>

<Context>
<Resource uri = "assembly: // firstspringnetapp/objects. xml"/>
<Resource uri = "config: // spring/objects"/>
</Context>
<Objects xmlns = "http://www.springframework.net"/> <! -- Required -->
</Spring>

</Configuration>

 

 

 

Iapplicationcontext CTX = contextregistry. getcontext ();
Console. writeline (CTX. GetObject ("persondao"). tostring ());

 

Now let's talk about spring. NET environment configuration first.

Code download

From: http://www.cnblogs.com/GoodHelper/archive/2009/10/25/SpringNET_Config.html

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.