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();
            }
        }
    }
  • 相关阅读:
    python多线程学习一
    https学习笔记三----OpenSSL生成root CA及签发证书
    https学习笔记二----基础密码学知识和python pycrypto库的介绍使用
    HTTPS学习笔记一----HTTPS的基础理论知识
    一只小鹅的2017
    python 全局变量的import机制
    一起来学设计模式-----工厂模式的实践
    一起来学设计模式-----创建型模式之抽象工厂
    一起来学设计模式-----创建型模式之工厂方法
    一起来学设计模式-----创建型模式之简单工厂
  • 原文地址:https://www.cnblogs.com/wucg/p/1783189.html
Copyright © 2011-2022 走看看