一、开发环境

系统: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. Swap Nodes in Pairs(链表操作)

    Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...

  2. java反射-使用反射来操纵方法

    一个类的主要成员时方法,辣么我们通过反射获取到一个类的所有方法信息后,总的寻找一种方式去操作调用这些方法,这样反射才有意义有意思. Method对象有一个方法invoke.      public O ...

  3. 加上mvc:resources后controller访问404

    之前因为静态资源访问,404,于是加上了类似的代码 <mvc:resources location="/resources/" mapping="/resource ...

  4. TCP网络库:Acceptor、TcpServer、TcpConnection

    Acceptor类:用于接收新的TCP连接,该类是内部class,供TcpServer使用,生命期由TcpServer控制 类成员: class Acceptor : boost::noncopyab ...

  5. MapReduce WordCount Combiner程序

    MapReduce WordCount Combiner程序 注意使用Combiner之后的累加情况是不同的: pom.xml <project xmlns="http://maven ...

  6. RelativeLayout不能居中的解决的方法

    在LinearLayout中有个让元素居中的办法就是.比方在LinearLayout里有个TextView.设置TextView的gravity能够让其居中. 而在Realative里设置这个不起作用 ...

  7. VC++6.0不能显示MSDN解决的方法

    1.搜索看系统是否有Vshelp.dll文件.没有则去站点下载一个 位操作系统直接将下载的文件放在C:\Windows\System32 位操作系统则放在C:\Windows\SysWOW64 3.点 ...

  8. JavaScript基础 -- DOM

    一.DOM全称 文档对象模型(Document Object Model) 二.DOM是什么 DOM可以说是制作动态页面的强有力工具.DOM不是JavaScript语言的一部分,而是内置在浏览器中的一 ...

  9. go2基本类型

    /* Go基本类型 布尔型:bool - 长度:1字节 - 取值范围:true, false - 注意事项:不可以用数字代表true或false 整型:int/uint - 根据运行平台可能为32或6 ...

  10. Codesys——AD_DA在PID控制中的作用

    1. 摘要 PID控制中用到AD/DA的输入/输出,给出其大致实现思路. 2. 思路 3. 总结 无