zoukankan      html  css  js  c++  java
  • Spring.net配置相关

    代码
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>

        
    <configSections>
            
    <sectionGroup name="common">
                
    <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
            
    </sectionGroup>
            
            
            
    <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="assembly://Model/Model.config/object_all.xml"/>            
                
                
    <!--<resource uri="D:\wucg\test\HelloWorldSpringDotnet\HelloWorldSpringDotnet\config\object_all.xml"/>-->
                
    <!--<resource uri="config://spring/objects"/>-->
                
    <!--<resource uri="assembly://程序集名/命名空间.文件夹名/资源名" />--> <!--xml的属性“生成操作”设为“嵌入资源”-->
                
    <!--<resource uri="assembly://HelloWorldSpringDotnet/HelloWorldSpringDotnet.config/object_all.xml"/>-->
            
            
    </context>
            
    <!--<objects xmlns="http://www.springframework.net">
                <object id="MyObject" type="HelloWorldSpringDotnet.MyCls" >
                </object>
            </objects>
    -->
        
    </spring>
    </configuration>

    using Spring.Core;
    using Spring.Context;
    using Spring.Context.Support;

    namespace HelloWorldSpringDotnet
    {
        
    class Program
        {
            
    static void Main(string[] args)
            {
                IApplicationContext context 
    = ContextRegistry.GetContext();
                MyCls o 
    = context.GetObject("MyObject"as MyCls;
                MyCls o2 
    = context.GetObject("MyObject"as MyCls;
                o.MyInt 
    = 10;
                o2.MyInt 
    = 20;

                Console.WriteLine(
    object.ReferenceEquals(o, o2));
                Console.WriteLine(
    "o.MyInt={0}",o.MyInt);
                Console.WriteLine(
    "o2.MyInt={0}", o2.MyInt);


                
    /* 法三:独立配置文件,xml编译时作为嵌入资源,最好
                 * e.g.:
                 * <!--<resource uri="assembly://程序集名/命名空间.文件夹名/资源名" />--> 
                 * <!--xml的属性“生成操作”设为“嵌入资源”-->            
                 * <!--<resource uri="assembly://Model/Model.config/object_all.xml"/>-->
                 * 
                    IApplicationContext context = ContextRegistry.GetContext();
                    object o = context.GetObject("MyObject");
                
    */

                
    //法2:
                
    //IApplicationContext context = new XmlApplicationContext(@"D:\wucg\test\HelloWorldSpringDotnet\HelloWorldSpringDotnet\config\object_all.xml");            
                
    //object o = context.GetObject("MyObject");
                
                
    /*法1:
                StaticApplicationContext context = new StaticApplicationContext();
                context.RegisterPrototype("MyCls1", typeof(MyCls), null);
                object o = context.GetObject("MyCls1");
               
                
    */ 


                Console.WriteLine(o);
                Console.ReadKey();
            }
        }
    }
  • 相关阅读:
    第六周
    第五周
    第四周
    第二周学习记录
    实验一 Linux初步认识
    java实验四
    java实验三
    为什么无密码认证能够有效
    关于父元素,子元素,同级元素的DOM操作技巧
    高效设计构建软件的十三条建议
  • 原文地址:https://www.cnblogs.com/wucg/p/1783189.html
Copyright © 2011-2022 走看看