1, create a new class Framework. CS
public class Framework{public Framework () {////todo: Add constructor logic here//} public string Name {set; get;}}
2. add a label to the index.aspx page
<div>
3. Index.aspx.cs
public partial class index:system.web.ui.page{ //define an injection point public Framework frameworkname {set; get;} protected void Page_Load (object sender, EventArgs e) { This.lblFramework.Text = this. Frameworkname.name;} }
There are two main ways to define an object, either directly in Web. config , or in an external configuration file.
4, directly defined in the Web. config , using Spring.Context.Support.DefaultSectionHandler . This can be defined directly in the configuration file.
<configSections> <!--Spring Configuration--<sectiongroup name= "Spring" > <section name= "Context" Type= "Spring.Context.Support.WebContextHandler, Spring.web"/> <!--support for defining objects in Web. config--<section Name= "Objects" type= "Spring.Context.Support.DefaultSectionHandler, Spring.core"/> </sectionGroup> </ configsections> <spring> <context> <resource uri= "config://spring/objects"/> </context& Gt <!--objects directly defined in Web. config--<objects> <object id= "framework" type= "Framework" ><!--class name-- <property name= "name" value= "Hello,world"/><!--property name, Value-</object> <!--Page Object-- <object type= "~/index.aspx" > <!--ref means the object being referenced--<property name= "FrameworkName" ref= "f Ramework "/><!--index.aspx page Property name--</object> </objects> </spring>
5. Browse index.aspx
6. Configure the object in a separate configuration file.
Create a folder in your Web site named Config to save the standalone configuration file.
In the Config folder, create an XML configuration file named objects.xml . Add A root element named objects, add the default namespace xmlns= "Http://www.springframework.net"
Locate the following schema file and copy to the VS installation directory:C:\Program Files (x86) \microsoft Visual Studio 10.0\xml\schemas
In this way, we have IntelliSense capabilities in the XML file.
Add the original object definition here.
<?xml version= "1.0" encoding= "Utf-8"? ><objects xmlns= "http://www.springframework.net" ><!--default namespace-- > <object id= "framework" type= "Framework" > <!--class name-- <property name= "name" value= " Hello,china "/> <!--property name, Value-- </object> <!--Page Object-- <object type=" ~/ Index.aspx "> <!--ref represents objects referenced-- <property name=" FrameworkName "ref=" framework "/> <! --index.aspx page Property name- </object></objects>
Remove the Objects configuration section that was originally configured in Web. config, replacing the configuration in the original context configuration section with the following.
<context> <resource uri= "~/config/objects.xml"/> <!--<resource uri= "config://spring/ Objects "/>--> </context>
6, re-browse index.aspx
Step-by-step learning spring.net--First program "Hello,world"