惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
G
Google Developers Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
S
SegmentFault 最新的问题
宝玉的分享
宝玉的分享
博客园 - Franky
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
月光博客
月光博客
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
小众软件
小众软件
Microsoft Security Blog
Microsoft Security Blog
Last Week in AI
Last Week in AI
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
爱范儿
爱范儿
J
Java Code Geeks
博客园 - 叶小钗
Engineering at Meta
Engineering at Meta
阮一峰的网络日志
阮一峰的网络日志

博客园 - IT 笔记

Subversion Revert File will not be shown in Modification Surprise vb.net WinForm don't require instance to access the instance value Properties.Settings show error 'System.Windows.Forms.PropertyStore' does not contain a definition for 'Settings' Add Image in MS Report RDLC by using Embedded Image 王爽汇编 Lab 13 Question 1, 用两个程序实现 王爽汇编语言 实验11 王爽汇编语言 检测点11.2 王爽 汇编语言程序课程设计1 王爽 汇编语言程序设计实验10,题三,数值转换。(Assembly experiment Convert HEX to Decimal and Show on screen ) 王爽 汇编语言程序设计 实验9 (Assembly Language Study) 王爽 汇编语言程序设计 检测点9.1 第2题 The NTVDM CPU has encountered an illegal instruction. CS:0006 IP:130a .... select files by multiple extension name Access Denied when running Spring.IocQuickStart.MovieFinder using vb.net read unix style text file How to install autotrace in fontforge My first postscript program .net 2 config A generic winform skeleton support interactive UI during large job process
Spring.NET Installation and setup the first program
IT 笔记 · 2011-12-08 · via 博客园 - IT 笔记

1. Download the file in blue box from website http://www.springsource.com/, then execute the exe file to install it

image

2. Create a sample porject called DataAccess in C# console program

3. Add C:\Program Files\Spring.NET 1.3.2\bin\net\2.0\release\Spring.Core.dll  (2.0 means framework 2)

The solution file is like

image

The code is like below

Program.cs

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Text;
   4: using Spring.Context;
   5: using Spring.Context.Support; 
   6: namespace DataAccess
   7: {
   8:   class MainApp
   9:   { 
  10:     static void Main()
  11:     {
  12:       DataAccessObject daoCategories = new Categories();
  13:       daoCategories.Run();
  14:  
  15:       DataAccessObject daoProducts = new Products();
  16:       daoProducts.Run();
  17:  
  18:       IApplicationContext context = ContextRegistry.GetContext(); 
  19:       DataAccessObject DAO = (DataAccessObject)context.GetObject("DataAccessObject");
  20:       DAO.Run();
  21:  
  22:       // Wait for user
  23:       Console.ReadKey();
  24:     }
  25:   }
  26:  
  27:   abstract class DataAccessObject
  28:   {
  29:     protected string connectionString; 
  30:  
  31:     public virtual void Connect()
  32:     {
  33:         Console.WriteLine("Connect '" + connectionString + "'"); 
  34:     }
  35:  
  36:     public abstract void Select();
  37:     public abstract void Process();
  38:  
  39:     public virtual void Disconnect()
  40:     {
  41:         Console.WriteLine("Discount\r\n");
  42:     }
  43:  
  44:     // The 'Template Method'
  45:     public void Run()
  46:     {
  47:       Connect();
  48:       Select();
  49:       Process();
  50:       Disconnect();
  51:     }
  52:   }
  53:   
  54:   class Categories : DataAccessObject
  55:   {
  56:     public override void Select()
  57:     {
  58:         Console.WriteLine("Get Categories"); 
  59:     }
  60:  
  61:     public override void Process()
  62:     {
  63:         Console.WriteLine("Process Categories"); 
  64:     }
  65:   }
  66:   
  67:   class Products : DataAccessObject
  68:   {
  69:     public override void Select()
  70:     {
  71:         Console.WriteLine("Get Products"); 
  72:     }
  73:  
  74:     public override void Process()
  75:     {
  76:         Console.WriteLine("Process Products"); 
  77:     }
  78:   }
  79: } 

App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
    </sectionGroup>
  </configSections>
  <spring>
    <context>
      <resource uri="spring.xml.config"/>
    </context> 
  </spring>
</configuration>

spring.xml.config

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
  <object id="DataAccessObject" type="DataAccess.Products">
    <property name="connectionString" value="C:\db\northwind.mdb"/>
  </object>
</objects>

Running the application, the output is like

image

Now modify the spring.xml.config as below, only change “Products” to “Categories”

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
  <object id="DataAccessObject" type="DataAccess.Categories">
    <property name="connectionString" value="C:\db\northwind.mdb"/>
  </object>
</objects>

The output will be changed to

image

See the red highlight, it has changed the program direction without recompile the exe.