Spring.Net学习笔记(5)-集合注入
2024-09-21 22:03:41
一、开发环境
系统: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();
}
}
}
四、说明
这边有个坑,花了我好长时间,具体解决看 问题汇总
最新文章
- Linux下设置环境变量
- RunLoop和autorelease的一道面试题
- WPF如何实现一款类似360安全卫士界面的程序?(共享源码!)
- MongoDB 3.0 用户创建
- 【noiOJ】p1794
- JAVA给图片加上水印
- eclipse快捷键调试总结【转】
- 【bzoj1047】理想的正方形
- 一个基于MINA框架应用的最简单例子
- 使用axis公布weblogic(一个)
- 用Node.JS+MongoDB搭建个人博客(安装环境)(一)
- python 第二天
- angular4.0如何引入外部插件2:declare方案
- 源码推荐:移动端商城(微信小程序源代码) WebView离线缓存
- jquery 加法 乘法运算 精确计算函数
- Android Studio模拟器磁盘空间不足(Not enough disk space to run AVD)
- Jquery相关插件
- 2017-6-5/MySQL分库分表
- 分布式超级账本Hyperledger里zookeeper的作用
- hadoop脑裂
热门文章
- codevs——1039 数的划分
- Swap Nodes in Pairs(链表操作)
- Ubuntu 16.04出现Can&#39;t open /etc/rc.d/init.d/functions的问题解决
- mybatis返回list很智能很简答的,只需要配置resultmap进行类型转换,你dao方法直接写返回值list<;对应的object>;就行了啊
- 【EasyUI】——可编辑的DataGrid
- qt-qml移动开发之在ios上开发和部署app流程简单介绍
- UGUI 实现Button长按效果(RepeatButton)
- Android一些网站介绍
- js执行“按回车”的动作
- commons-fileupload 组件实现文件上传