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

推荐订阅源

WordPress大学
WordPress大学
O
OpenAI News
Y
Y Combinator Blog
MyScale Blog
MyScale Blog
C
Check Point Blog
Vercel News
Vercel News
小众软件
小众软件
The Register - Security
The Register - Security
N
News and Events Feed by Topic
腾讯CDC
S
SegmentFault 最新的问题
H
Heimdal Security Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Secure Thoughts
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Schneier on Security
Schneier on Security
G
GRAHAM CLULEY
云风的 BLOG
云风的 BLOG
S
Schneier on Security
J
Java Code Geeks
L
LINUX DO - 最新话题
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Privacy & Cybersecurity Law Blog
Forbes - Security
Forbes - Security
Cisco Talos Blog
Cisco Talos Blog
L
LINUX DO - 热门话题
Scott Helme
Scott Helme
爱范儿
爱范儿
GbyAI
GbyAI
Simon Willison's Weblog
Simon Willison's Weblog
L
Lohrmann on Cybersecurity
Cloudbric
Cloudbric
W
WeLiveSecurity
The Hacker News
The Hacker News
V
V2EX
Last Week in AI
Last Week in AI
Hacker News: Ask HN
Hacker News: Ask HN
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Blog — PlanetScale
Blog — PlanetScale
Cyberwarzone
Cyberwarzone
Google Online Security Blog
Google Online Security Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
S
Security @ Cisco Blogs
P
Proofpoint News Feed
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security
U
Unit 42
Webroot Blog
Webroot Blog
Martin Fowler
Martin Fowler
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed

博客园 - 紫色阴影

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

很简单,不是吗?