zoukankan      html  css  js  c++  java
  • 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集成子类

  • 相关阅读:
    php.h: No such file or directory
    检查日期是否为节假日api
    Linux下实现秒级的crontab定时任务
    Apache 两种mpm prefork 和 worker 的区别
    centos6 安装mysql报错Requires: libc.so.6(GLIBC_2.14)
    Yii2 高级模板添加更多Application
    Yii2 assets注册的css样式文件没有加载
    Yii rbac原理和实践
    Yii2 ActiveRecord save失败
    Yii2 手动安装yii2-imagine插件
  • 原文地址:https://www.cnblogs.com/ecollab/p/6155047.html
Copyright © 2011-2022 走看看