1) 新建控制台项目
2) 添加一个类:Test.cs
Test.cs代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace sprintTest
{
class Test
{
public Test() { }
public void Function()
{
Console.Out.WriteLine("--- Press <return> to quit ---");
Console.ReadLine();
}
}
}
3) 应用程序配置文件
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="config://spring/objects"/>
</context>
<objects xmlns="http://www.springframework.net">
<object id="Test" type="sprintTest.Test,sprintTest"></object>
</objects>
</spring>
</configuration>
注意: 配置类的信息,是在objects标签下,其他是Sprint.net配置.
4) 添加dll 应用: Spring.Core.dll 和 Common.Logging.dll
调用代码:
using System;
using System.Collections.Generic;
using System.Text;
using Spring.Context;
using Spring.Context.Support;
namespace sprintTest
{
class Program
{
static void Main(string[] args)
{
IApplicationContext ctx = ContextRegistry.GetContext();
Test test = (Test)ctx.GetObject("Test");
test.Function();
}
}
}