zoukankan      html  css  js  c++  java
  • C#简单应用spring的例子

    接口定义

    
    namespace SpringDemo
    {
        interface IOper
        {
            void Say();
        }
    }
    
    

    此接口的两个实现
    实现1

    using System;
    
    namespace SpringDemo
    {
        class Impl1 : IOper
        {
            #region IOper 成员
    
            public void Say()
            {
                Console.WriteLine("I'm impl 1");
            }
    
            #endregion
        }
    }
    
    

    实现2

    using System;
    
    namespace SpringDemo
    {
        class Impl1 : IOper
        {
            #region IOper 成员
    
            public void Say()
            {
                Console.WriteLine("I'm impl 1");
            }
    
            #endregion
        }
    }
    
    

    调用部分

    
    namespace SpringDemo
    {
        class App
        {
            public IOper oper { get; set; }
            public void Run()
            {
                this.oper.Say();
            }
        }
    }
    
    

    配置文件

    <?xml version="1.0" encoding="utf-8" ?>
    <objects xmlns='http://www.springframework.net'
             xmlns:db="http://www.springframework.net/database"
             xmlns:tx="http://www.springframework.net/tx"
             default-autowire="byName" default-lazy-init="true">
    	<object name="oper" type="SpringDemo.Impl2, SpringDemo"/>  
    </objects>
    

    主函数

    using System;
    using Spring.Context;
    using Spring.Context.Support;
    
    namespace SpringDemo
    {
        class Program
        {
            static void Main(string[] args)
            {
                string config = "applicationContext.xml";
                IApplicationContext context = new XmlApplicationContext(config);
                IOper oper = (IOper)context.GetObject("oper");
                App a = new App();
                a.oper = oper;
                a.Run();
                Console.Read();
            }
        }
    }
    
    
  • 相关阅读:
    1414 冰雕
    1475 建设国家(优先队列)
    Digit Division
    Sleep Buddies
    Reverse and Compare(DP)
    1536 不一样的猜数游戏
    Genealogical tree
    网站日志实时分析工具GoAccess使用
    CentOS下一键安装Openstack
    权重轮询调度算法(WeightedRound-RobinScheduling)-Java实现2
  • 原文地址:https://www.cnblogs.com/wardensky/p/4528428.html
Copyright © 2011-2022 走看看