一、开发环境

系统: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. JVM(三):深入分析Java字节码-上

    JVM(三):深入分析Java字节码-上 字节码文章分为上下两篇,上篇也就是本文主要讲述class文件存在的意义,以及其带来的益处.并分析其内在构成之一 ---字节码,而下篇则从指令集方面着手,讲解指 ...

  2. 洛谷 U41571 Agent2

    U41571 Agent2 题目背景 炎炎夏日还没有过去,Agent们没有一个想出去外面搞事情的.每当ENLIGHTENED总部组织活动时,人人都说有空,结果到了活动日,却一个接着一个咕咕咕了.只有不 ...

  3. FlashChart json数据配置 中文文档

    http://www.riaos.com/ria/2274 FlashChart json数据配置说明 有朋友要用flashchart,感觉这个还不错.就整理了一份文档. 基本包括了所有json配置的 ...

  4. java MAT 分析

    java MAT 分析 http://blog.csdn.net/qeqeqe236/article/details/43577857 https://www.cnblogs.com/AloneSwo ...

  5. 基于cocos2d-x-3.2学习Box2D(一)

    cocos版本号:cocos2d-x-3.2 环境:Win7+VS2013 因为一些太底层的实现我如今的能力学习不到,仅仅能做一些简单的笔记,供以后翻阅.假设别人可以得到帮助,莫大的荣幸. 一.创建世 ...

  6. tesnorflow Batch Normalization

    1.train或者从checkpoint restore后发现moving_mean和moving_variance都是0和1 bn1_mean = graph.get_tensor_by_name( ...

  7. 三星手机root后开启调试模式

    背景说明:三星手机高版本的手机进行root后也无法安装xposed,无法开启debuggable,使用androistdio无法进行调试. 1 .连接ddms无法显示正在运行的进程. 2.安装mpro ...

  8. Matlab7.1——启动时只显示Logo

    1. 现象 Matlab7.1在启动时只显示Matlab的Logo: 2. 解决方法 听我的吧,这个是官方办法,我也亲自试过了1结束matlab进程:2在C:\user\APPDATA\Roaming ...

  9. brew安装PHP7 swoole

    环境: 系统:mac os High Sierra 10.13.3 php版本:7.0.27_19 1.安装homebrew brew 又叫Homebrew,是Mac OSX上的软件包管理工具,能在M ...

  10. mysql将查询结果导出csv文件的方法into outfile

    例句: select * from table_name into outfile '/tmp/tmp.csv' fields terminated by ',';   详解: ① into outf ...