惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 紫色阴影

Android ellipsize的小问题 腾讯招聘贴 有意向的人发邮件或者msn Asp.net MVC tips -- 也做为 要写漂亮的代码 (2) - 紫色阴影 要写漂亮的代码 (1) 在团队中如何推行一项新的实践 - 紫色阴影 事件驱动的javascript 验收测试的自动化 - 紫色阴影 项目中的技术风险 欢迎需求变动,拥抱变化 成为MVP 使用动态数据库访问对象 使用Spring.Net对Web页面进行依赖注入 如何把握设计的尺度 初窥Managed Extensibility Framework - 紫色阴影 Bug驱动开发简介 持续集成简介 简单介绍使用WCF的Web编程模型开发REST风格的Web Service 尝试使用WatiN进行TDD - 紫色阴影 关于站立式会议
Unity的属性注入
紫色阴影 · 2008-05-23 · via 博客园 - 紫色阴影

  Unity不用太多介绍,园子里很多Unity入门的文章。我一直以来也没有时间研究,直到昨天看了深入 Unity 1.x 依赖注入容器之一:入门才见识到Unity的真面目。初一看某些地方感觉和Google的Guice很相似,Guice提供利用Annotation来进行注入,而Unity则提供[Dependency]的Property,两者有异曲同工之效。Unity还有更多的创新,比如InjectionMethod,在很多场合它也能被用到。

  但是看后又觉得[Dependency]注入的方式太具有侵入性了,如果我现在有大量的代码,想加上IOC。那么就不得不在每个注入点加上[Dependency]和Using... 这是很危险的。我们引入Unity帮助创建对象,但它却分散到代码中的各个地方,难以被改变,其违背了“高内聚,低耦合”的原则。

  既然Unity允许使用配置文件进行初始化,我就想它应该也支持配置文件指定属性注入。翻查了官方文档后,发现Unity的确支持。不多说,放出一个Log的小例子,各位看了就会明白。

接口及类:

image

Main函数

image

配置文件

image

很简单,不是吗?