Spring.NET 基本使用
来源:互联网 发布:网络大电影发行协议 编辑:程序博客网 时间:2024/06/04 19:51
以前一直在使用Spring,虽然知道有Spring.NET这个东西,一直也没有时间去尝试,最近想写一个"热拔插"的高扩展性的组件,想探索下使用Spring.NET,写了一个简单的Demo作为开始。
1.安装
使用NuGet命令行
Install-Package Spring.Core2.Test
using System;using System.IO;using Spring.Context.Support;namespace SpringNetBasic{ public class GameChannel { public string ChannelName { set; get; } public string ChannelId { set; get; } } public class ChannelAccount { public string AccountName { set; get; } public string AccountId { set; get; } } public class TestDemo { public GameChannel Channel { set; get; } public ChannelAccount Account { set; get; } public string GetInfo() { return Channel.ChannelName + Account.AccountName; } } class Program { static void Main(string[] args) { var context = new XmlApplicationContext(Directory.GetCurrentDirectory() + @"\object.xml"); var test = context.GetObject("TestDemo") as TestDemo; if (test != null) Console.WriteLine(test.GetInfo()); Console.ReadKey(); } }}3.object.xml
<?xml version="1.0" encoding="utf-8" ?><objects xmlns="http://www.springframework.net"> <object id="GameChannel" type="SpringNetBasic.GameChannel"> <property name="ChannelName" value="aaa"/> </object> <object id="ChannelAccount" type="SpringNetBasic.ChannelAccount"> <property name="AccountName" value="bbb"/> </object> <object id="TestDemo" type="SpringNetBasic.TestDemo"> <property name="Channel" ref="GameChannel"/> <property name="Account" ref="ChannelAccount"/> </object></objects>
4.结果
5.总结
Spring.NET通过配置的形式完成以来注入,相比其他以来注入组件,不需要写Attribute,这里比较简洁,跟Spring几乎一模一样。
0 0
- Spring.NET 基本使用
- Spring.Net的基本使用
- spring.net基本使用:控制反转和依赖注入
- spring AspectJ 基本使用
- Spring的基本使用
- spring 基本使用
- Spring retry基本使用
- Spring Profile基本使用
- Spring Redis基本使用
- spring +springmvc 基本使用
- Spring IOC 基本使用
- spring基本使用
- Spring task基本使用
- Spring retry基本使用
- spring的基本使用
- Spring cache基本使用
- spring.net的使用
- spring定时任务--基本使用
- c# 窗体插入WORD
- Android保存图片到系统图库
- string ut8编码 需要对"/"转码
- Activiti工作流(1):activiti简介
- python2.7+django1.8+mysql的模版显示数据的例子
- Spring.NET 基本使用
- leetcode 238:Product of Array Except Self
- GCD同步问题
- POJ——1979Red and Black
- session与cookie整理
- 无法定位 xxxx 与动态链接库 avcodec-xx.dll上
- Debug模式和Release模式区别
- memcache简单使用
- python pip国内镜像