namespace Tuzi.Models.IService { public interface IPersonService { string say(string words); }
namespace Tuzi.Models.Service { public class PersonService:IPersonService { public string say(string words) { return words; } } }
namespace Tuzi.Controllers { public class TuziController : Controller { // // GET: /Tuzi/ IPersonService PersonService { get; set; } public string msg { get; set; } public ActionResult Index() { return Content(PersonService.say("spring.net和mvc3") + msg); } } }
<?xml version="1.0" encoding="utf-8" ?> <objects xmlns="http://www.springframework.net"> <object type="Tuzi.Controllers.TuziController,Tuzi" singleton="false"> <property name="Msg" value="msginfo" /> <property name="PersonService" ref="PersonServiceObj" /> </object> <object id="PersonServiceObj" type="Tuzi.Models.Service.PersonService,Tuzi" > </object> </objects>
<configSections> <!--spring对象和上下文配置--> <sectionGroup name="spring"> <!--<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" /> <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />--> <section name="context" type="Spring.Context.Support.MvcContextHandler, Spring.Web.Mvc3"/> </sectionGroup> </configSections> <!--spring配置 begin--> <spring> <context> <resource uri="file://~/Config/Controllers.xml"/> </context> </spring>
Global.asax文件 修改MvcApplication : Spring.Web.Mvc.SpringMvcApplication
在写配置文件时,默认是没有提示的,将spring.net doc下所有的.xsd复制到以下目录里就行了
Spring.net强大的功能,简化企业开发。