一、开发环境

系统: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)-集合注入的更多相关文章

  1. Spring.NET学习笔记8——集合类型的注入(基础篇)

    1.基础类 public class Happy    {        public override string ToString()        {            return &q ...

  2. Spring.NET学习笔记6——依赖注入(应用篇)

    1. 谈到高级语言编程,我们就会联想到设计模式:谈到设计模式,我们就会说道怎么样解耦合.而Spring.NET的IoC容器其中的一种用途就是解耦合,其最经典的应用就是:依赖注入(Dependeny I ...

  3. Spring.Net学习笔记(6)-方法注入

    一.开发环境 系统:win10 编译器:VS2013 二.涉及程序集 Spring.Core.dll 1.3.1 Common.Logging.dll 三.开发过程 1.项目结构 2.编写Mobile ...

  4. Spring.Net学习笔记(2)-依赖注入

    一.开发环境 操作系统:Win10 编译器:VS2013 framework版本:.net 4.5 Spring版本:1.3.1 二.涉及程序集 Spring.Core.dll Common.Logg ...

  5. 【转】Spring.NET学习笔记——目录

    目录 前言 Spring.NET学习笔记——前言 第一阶段:控制反转与依赖注入IoC&DI Spring.NET学习笔记1——控制反转(基础篇) Level 200 Spring.NET学习笔 ...

  6. Spring.NET学习笔记——目录(原)

    目录 前言 Spring.NET学习笔记——前言 第一阶段:控制反转与依赖注入IoC&DI Spring.NET学习笔记1——控制反转(基础篇) Level 200 Spring.NET学习笔 ...

  7. Spring源码学习笔记9——构造器注入及其循环依赖

    Spring源码学习笔记9--构造器注入及其循环依赖 一丶前言 前面我们分析了spring基于字段的和基于set方法注入的原理,但是没有分析第二常用的注入方式(构造器注入)(第一常用字段注入),并且在 ...

  8. Spring框架学习笔记(1)

    Spring 框架学习笔记(1) 一.简介 Rod Johnson(spring之父) Spring是分层的Java SE/EE应用 full-stack(服务端的全栈)轻量级(跟EJB比)开源框架, ...

  9. SpringBoot + Spring Security 学习笔记(五)实现短信验证码+登录功能

    在 Spring Security 中基于表单的认证模式,默认就是密码帐号登录认证,那么对于短信验证码+登录的方式,Spring Security 没有现成的接口可以使用,所以需要自己的封装一个类似的 ...

随机推荐

  1. 技术杂记之:在阿里云centos7上部署JDK MYSQL TOMCAT

    今日小编闲来无事,乘着公司新项目即将上线之际,在阿里云上整了一台centos作为测试机.原本以为一个小时搞定,结果还是花了一点小小时间.不管怎么说,记录下来,给各位小白当成课后甜点吧. 价格 先上价格 ...

  2. JSTL-函数标签库

    主页:http://www.cnblogs.com/EasonJim/p/6958992.html的分支页. 一.fn:contains() fn:contains()函数决定了一个输入字符串是否包含 ...

  3. elk实时日志分析平台部署搭建详细实现过程

    原文:http://blog.csdn.net/mchdba/article/details/52132663 1.ELK平台介绍 在搜索ELK资料的时候,发现这篇文章比较好,于是摘抄一小段:以下内容 ...

  4. CentOS 7防火墙服务FirewallD指南

    CentOS 7防火墙服务FirewallD指南 作者:chszs,未经博主同意不得转载.经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs 防火墙是一种位于内部网 ...

  5. SGU 439 A Secret Book

    解法: 对于第二个串,循环移动能得到的字典序最小的串,可以直接用最小表示法搞定. 然后用最小表示的第二个串和第一个串做两次扩展KMP,一次正常求,另外一次将两个串都反转一下,然后扫一遍ex[]数组 # ...

  6. Elasticsearch学习系列之配置文件详解

    ################################### Cluster ################################### #定义集群名称,默认是elasticse ...

  7. DHCP Snooping的实现

    DHCP Snooping的实现 DHCP Snooping的实现 主要作用:1.防止在动态获得IP地址的网络环境中用户手动配置PC的IP地址;2.防止A用户的PC静态配置的IP地址顶掉B用户PC动态 ...

  8. 【Hibernate】Hibernate的多表查询

    在<[Hibernate]Hibernate的聚类查询.分组查询.排序与时间之差>(点击打开链接)一文中已经讲述过怎样利用HQL语句代替SQL语句.进行聚类查询.分组查询.排序与时间之差的 ...

  9. oracle导入命令,记录一下 数据库日志太大,清理日志文件

    oracle导入命令,记录一下 工作中用到了,这个命令,记录一下,前提要安装imp.exe imp PECARD_HN/PECARD_HN@127.0.0.1:1521/orcl file=E:\wo ...

  10. ServiceStack学习之一准备工作

    GitHub:https://github.com/ServiceStack/ServiceStack/wiki 官网介绍的前期准备知识: Wikipedia article about HTTP a ...