您的位置:知识库 » 软件测试

[Spring.NET IoC] 之二:配置文件

作者: Q.yuhen  来源: Q.yuhen  发布时间: 2008-08-17 23:03  阅读: 5736 次  推荐: 1   原文链接   [收藏]  
Spring.NET IoC 支持2种配置文件方式:

1. 应用程序配置文件

app.config / web.config
<?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 xmlns="http://www.springframework.net">
      <object id="HelloWorld" type="ConsoleApplication1.SpringNet.HelloWorld, Learn.CUI" >
      </object>
    </objects>

  </spring>
</configuration>

test.cs
      IApplicationContext context = ContextRegistry.GetContext();
      object o = context.GetObject("HelloWorld");

2. 独立配置文件

springtest.xml
<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.springframework.net
         http://www.springframework.net/xsd/spring-objects.xsd">
  
  <object id="HelloWorld" type="ConsoleApplication1.SpringNet.HelloWorld, Learn.CUI">
  </object>
</objects>

test.cs
IApplicationContext context = new XmlApplicationContext(@"springtest.xml");
object o = context.GetObject("HelloWorld");

建议使用独立的配置文件,应用程序配置文件已经被塞入太多内容了。Spring.NET 还支持很多高级的配置文件功能,将在后面做进一步介绍。
1
0
 

软件测试热门文章

    软件测试最新文章

      最新新闻

        热门新闻