Spring.Net学习笔记(5)-集合注入
一、开发环境
系统:Win10
编译器:VS2013
.net版本:.net framework4.5
二、涉及程序集
Spring.Core.dll 1.3.1
Common.Loggin.dll
三、开发过程
1.项目结构

2.编写Person.cs
namespace SpringNetSetDi
{
public class Person
{
public string RealName { get; set; }
public string NickName { get; set; }
public string LoginName { get; set; }
public string ShowName { get; set; }
}
}
3.编写Animal.cs
namespace SpringNetSetDi
{
public class Animal
{
public string Name { get; set; }
public IList TypeList { get; set; }
}
}
4.编写Zoo.cs
namespace SpringNetSetDi
{
public class Zoo
{
public List<Animal> AnimalList { get; set; }
}
}
5.编写WebSetting.cs
namespace SpringNetSetDi
{
public class WebSetting
{
public IDictionary<int, string> PrintSetting { get; set; }
}
}
6.配置文件App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<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="config://spring/objects"></resource>
</context>
<objects xmlns="http://www.springframework.net">
<!--01设置空值-->
<object name="person" type="SpringNetSetDi.Person,SpringNetSetDi">
<property name="ShowName" value="Kimisme"></property>
<property name="RealName" value=""></property>
<property name="NickName">
<value></value>
</property>
<property name="LoginName">
<null/>
</property>
</object>
<!--02IList类型注入-->
<object name="animal" type="SpringNetSetDi.Animal,SpringNetSetDi">
<property name="TypeList">
<list element-type="string">
<value>哺乳类</value>
<value>鸟类</value>
<value>爬行类</value>
<value>昆虫类</value>
<value>两栖类</value>
</list>
</property>
</object>
<!--03泛型List注入-->
<object name="zoo" type="SpringNetSetDi.Zoo,SpringNetSetDi">
<property name="AnimalList">
<list element-type="SpringNetSetDI.Animal,SpringNetSetDi">
<object type="SpringNetSetDi.Animal,SpringNetSetDi">
<property name="Name" value="Eagle"></property>
<property name="TypeList">
<list element-type="string">
<value>鸟类</value>
</list>
</property>
</object>
</list>
</property>
</object>
<!--04Dictionary注入-->
<object name="webSetting" type="SpringNetSetDi.WebSetting,SpringNetSetDi">
<property name="PrintSetting">
<dictionary key-type="int" value-type="string">
<entry key="1" value="默认打印"></entry>
<entry key="2" value="个性打印"></entry>
</dictionary>
</property>
</object>
</objects>
</spring>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
7.控制台代码
namespace SpringNetSetDi
{
class Program
{
static void Main(string[] args)
{
IApplicationContext context = ContextRegistry.GetContext();
Person person = context.GetObject("person") as Person; Animal animal = context.GetObject("animal") as Animal; Zoo zoo = context.GetObject("zoo") as Zoo;
Console.ReadKey();
}
}
}
四、说明
这边有个坑,花了我好长时间,具体解决看 问题汇总
Spring.Net学习笔记(5)-集合注入的更多相关文章
- Spring.NET学习笔记8——集合类型的注入(基础篇)
		
1.基础类 public class Happy { public override string ToString() { return &q ...
 - Spring.NET学习笔记6——依赖注入(应用篇)
		
1. 谈到高级语言编程,我们就会联想到设计模式:谈到设计模式,我们就会说道怎么样解耦合.而Spring.NET的IoC容器其中的一种用途就是解耦合,其最经典的应用就是:依赖注入(Dependeny I ...
 - Spring.Net学习笔记(6)-方法注入
		
一.开发环境 系统:win10 编译器:VS2013 二.涉及程序集 Spring.Core.dll 1.3.1 Common.Logging.dll 三.开发过程 1.项目结构 2.编写Mobile ...
 - Spring.Net学习笔记(2)-依赖注入
		
一.开发环境 操作系统:Win10 编译器:VS2013 framework版本:.net 4.5 Spring版本:1.3.1 二.涉及程序集 Spring.Core.dll Common.Logg ...
 - 【转】Spring.NET学习笔记——目录
		
目录 前言 Spring.NET学习笔记——前言 第一阶段:控制反转与依赖注入IoC&DI Spring.NET学习笔记1——控制反转(基础篇) Level 200 Spring.NET学习笔 ...
 - Spring.NET学习笔记——目录(原)
		
目录 前言 Spring.NET学习笔记——前言 第一阶段:控制反转与依赖注入IoC&DI Spring.NET学习笔记1——控制反转(基础篇) Level 200 Spring.NET学习笔 ...
 - Spring源码学习笔记9——构造器注入及其循环依赖
		
Spring源码学习笔记9--构造器注入及其循环依赖 一丶前言 前面我们分析了spring基于字段的和基于set方法注入的原理,但是没有分析第二常用的注入方式(构造器注入)(第一常用字段注入),并且在 ...
 - Spring框架学习笔记(1)
		
Spring 框架学习笔记(1) 一.简介 Rod Johnson(spring之父) Spring是分层的Java SE/EE应用 full-stack(服务端的全栈)轻量级(跟EJB比)开源框架, ...
 - SpringBoot + Spring Security 学习笔记(五)实现短信验证码+登录功能
		
在 Spring Security 中基于表单的认证模式,默认就是密码帐号登录认证,那么对于短信验证码+登录的方式,Spring Security 没有现成的接口可以使用,所以需要自己的封装一个类似的 ...
 
随机推荐
- cn_windows_10_multiple_editions_version_1607_updated_jul_2016_x64
			
ed2k://|file|cn_windows_10_multiple_editions_version_1607_updated_jul_2016_x64_dvd_9056935.iso|43471 ...
 - GNS3模拟的硬件
			
Hardware emulated by GNS3 Cisco 1700 Series 1700s have one or more interfaces on the motherboard, 2 ...
 - CSS+Jquery实现QQ分组列表
			
实现效果图如下: 说明: 1.css隐藏分组下的好友内容: 2.Jquery实现点击分组项事件,实现好友内容的显示和隐藏: 3.样式1,可展开多个分组:样式2,只能有一个分组展开: 源码: <! ...
 - js 计算获取鼠标相对某个点的移动旋转角度
			
// 旋转角度 function getAngle(cen, first, second) { // cen : 中心点 [0,0] // first : 开始点 [1,3] // second : ...
 - json序列化后的是字符串,不是二进制。是字符串!!!确定不是二进制!!!
			
1.现有一个自定义对象需要储存到sql数据库中去.这个对象里面属性很多,甚至包含一些元素量打到几十万的List集合属性.本人试着使用JSON序列化这个对象,储存到数据库,报maxjsonlength超 ...
 - Atitit.auto complete  自己主动完毕控件的实现总结
			
Atitit.auto complete 自己主动完毕控件的实现总结 1. 框架选型 1 2. 自己主动完毕控件的ioc设置 1 3. Liger 自己主动完毕控件问题 1 4. 官网上的code ...
 - bootstrap 时间控件
			
近期使用了bootstrap的UI感觉确实非常美丽,非常值得学习和使用. 以下先简单了解下bootstrap的时间控件. 这个时间控件使用起来还是很的简单.仅仅须要引入主要的css和js就能够了 须要 ...
 - rk3188调试记录
			
1.编译 # . build/envsetup.sh # lunch 7 7. PI3910-user 1.电池部分 init.rc启动healthd-charger服务.对电池进行检測 se ...
 - tf.float32 implicity
			
简介 | TensorFlow https://tensorflow.google.cn/programmers_guide/low_level_intro 我们来构建一个简单的计算图.最基本的指 ...
 - 阿里电话面试问题----100万个URL怎样找到出现频率最高的前100个?
			
内推阿里电话面试中面试官给我出的一个题: 我想的头一个解决方式.就是放到stl 的map里面对出现的频率作为pair的第二个字段进行排序.之后依照排序结果返回: 以下口说无凭,show your co ...