zoukankan      html  css  js  c++  java
  • mvc3结合spring.net-依赖注入


    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强大的功能,简化企业开发。

  • 相关阅读:
    lazyload is not a function解决方式
    APK反编译(Linux环境下)
    讲解图片压缩的文章
    startActivityForResult相关的
    把APP做成libary的注意事项
    ViewPager+Fragment,Fragment会预加载的问题
    FragmentTabHost使用注意
    使用ReTrofit做缓存(结合上拉加载和下拉刷新)
    极光推送,极光IM使用指南(AndroidStudio)
    AndroidStudio使用注意事项
  • 原文地址:https://www.cnblogs.com/zjflove/p/3502529.html
Copyright © 2011-2022 走看看