• dependency injection


    This article is about the DI of spring.net.

    The underlying statement demonstrates how the spring.net works.

    First:Config your file App.config as follows.

    View Code
    <?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>
    <object name="MyDataAccess" type="DataAccessComponent.DefaultDataAccess,DataAccessComponent" />
    <object name="jialefuDataAccess" type="DataAccessComponent.jialefu,DataAccessComponent" />
    </objects>
    </spring>
    </configuration>

    Please pay attention on the node of <object />.It contains the information of name,class,assembly.It is the reason why you

    can activate specific instance(that is [assembly]class) according to the name.

    Second.

    You can create your arbitrary instance in your program.

    View Code
    IApplicationContext context = ConfigurationManager.GetSection("spring/context") as IApplicationContext;

    IDataAccess dac
    = context.GetObject("MyDataAccess") as IDataAccess;
    var r1
    = dac.ExecuteNonQuery("");

    IDataAccess da
    = context.GetObject("jialefuDataAccess") as IDataAccess;
    var r
    = da.ExecuteNonQuery("");

  • 相关阅读:
    HTML表格的简单使用1
    守卫路由使用
    CSS高度塌陷问题解决方案
    CSS导航条nav简单样式
    Linux学习
    TYpeScript接口的使用
    javaScript中自定义sort中的比较函数,用于比较字符串长度,数值大小
    給eclipse添加字体,设置字体
    tomcat自动URLDecode解码问题(+号变空格)
    时间管理
  • 原文地址:https://www.cnblogs.com/cnbwang/p/2091855.html
Copyright © 2020-2023  润新知