spring.net使用
1.方法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; namespace SpringTest { public class Person:IPerson { #region IPerson 成员 public void Actor(string msg) { MessageBox.Show(msg); } #endregion } }
2.接口
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SpringTest { public interface IPerson { void Actor(string msg); } }
3.调用方式
using Spring.Dao; using Spring.Data; using Spring.Context.Support; using Spring.Context; private void btnSpring_Click(object sender, EventArgs e) { IApplicationContext ctx = ContextRegistry.GetContext(); IPerson ps = ctx.GetObject("Person") as IPerson; ps.Actor("spring"); }
4.web.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"> <description>一个简单的控制反转例子</description> <object id="Person" type="SpringTest.Person, SpringTest" /> </objects> </spring> </configuration>
-------此处无银三百两------