spring.net

Spring.Net有两个很重要的感念就是IoC(控制反转)和DI(依赖注入)。

 IoC。英文全称Inversion of Control。控制反转。DI。英文全称Dependency Injection。依赖注入。简而言之,IoC就是创建对象,DI就是创建对象的时候。进行初始化。

AOP

Unity(.net自带)解决IoC、DI

<?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"/>
      <!--指定配置文件-->
      <resource uri="file://service.xml"/>
    </context>
    <objects xmlns="http://www.springframework.net">
      <description>An  example that demonstrates simple IoC features.</description>
      <!--<object name="UserInfoService" type="Eco.Web.SpringNet.UserInfoService, Eco.Web.SpringNet">
        <property name="userName" value="张三"/>
        <property name="person" ref="PersonDef"/>
      </object>
      <object name="PersonDef" type="Eco.Web.SpringNet.Person, Eco.Web.SpringNet">
        <property name="Age" value="20"/>
      </object>-->
    </objects>
  </spring>
</configuration>

选中service.xml文件,点击属性,选择[复制到输出目录][始终复制]

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
  <description>An  example that demonstrates simple IoC features.</description>

  <!--名称                     类全名称                           程序集名称-->
  <object name="UserInfoService" type="Eco.Web.SpringNet.UserInfoService, Eco.Web.SpringNet">
    <!--值传递属性-->
    <property name="userName" value="张三"/>
    <!--引用传递属性(复杂数据类型)-->
    <property name="person" ref="PersonDef"/>
  </object>
  <object name="PersonDef" type="Eco.Web.SpringNet.Person, Eco.Web.SpringNet">
    <property name="Age" value="20"/>
  </object>
</objects>

 引用mvc所需的spring所需的动态库

修改Global.asax.cs中public class MvcApplication : SpringMvcApplication集成子类

原文地址:https://www.cnblogs.com/ecollab/p/6155047.html