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

推荐订阅源

T
Tor Project blog
T
The Blog of Author Tim Ferriss
WordPress大学
WordPress大学
H
Help Net Security
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享
博客园 - 司徒正美
Jina AI
Jina AI
雷峰网
雷峰网
博客园_首页
博客园 - 三生石上(FineUI控件)
G
Google Developers Blog
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Forbes - Security
Forbes - Security
T
Threatpost
V
Visual Studio Blog
A
Arctic Wolf
Microsoft Azure Blog
Microsoft Azure Blog
Security Latest
Security Latest
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
P
Privacy & Cybersecurity Law Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Spread Privacy
Spread Privacy
N
News and Events Feed by Topic
Vercel News
Vercel News
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
NISL@THU
NISL@THU
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
PCI Perspectives
PCI Perspectives
博客园 - 【当耐特】
IT之家
IT之家
S
Secure Thoughts
Engineering at Meta
Engineering at Meta
阮一峰的网络日志
阮一峰的网络日志
Cisco Talos Blog
Cisco Talos Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
月光博客
月光博客
Latest news
Latest news
小众软件
小众软件
Attack and Defense Labs
Attack and Defense Labs
I
Intezer
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
大猫的无限游戏
大猫的无限游戏

博客园 - TG.Yang's IT Space

提高工作效率之数据库工具 Unity(3) Unity(2)生命周期 (转)常用的js代码 转:Oracle数据导入导出imp/exp命令 AspNet2.0页面生命周期(转) offsetLeft,Left,clientLeft的区别 发邮件窗体【支持编辑邮件模板,使用wse多线程上传附件及发邮件(带附件)】以及在服务器端自动发邮件 (mark)Oracle Update Statements Oracle 8i and 9i分析函数(转) BlogEngine.net学习(一)——实体类 row_number()over函数的使用(转) Community Server 资源 13个在线web2.0风格生成器 jQuery1.2选择器(转) 键盘输入工作原理 ORACLE 中ROWNUM用法总结 SQLServer和Oracle的常用函数对比 如何在Oracle里实现自增
Unity(1)控制反转
TG.Yang's IT Space · 2009-05-26 · via 博客园 - TG.Yang's IT Space

控制反转

依赖注入方式 DI Types(Dependency injection)

接口注入

     在接口中定义需要注入的信息。

    首先定义一个接口,组件的注入将通过这个接口进行,该接口应由组件提供者提

供,任何想使用该组件的类都必须实现这个接口。

    public interface ILog

   {

void Log(string message);

   }

   public interface ILogInject

  {

    void InjectLog(ILog log);

   }

   public class client:ILogInject

  {

  }

抽象工厂模式

将对象间的依赖关系转移到接口上,在调用时由容器来组装

构造函数注入

根据构造函数的类型调用Create方法建立实体对象,然后将对象传给构造函数

降低构造函数与实体对象之间的关联性

属性注入

与构造函数注入基本类似

Unity特点:

1.支持自定义容器

2.对要注入的类型没限制,除了属性注入和方法注入需要【Dependency】特性标注,对类声明没特别要求

3.支持容器层次结构

4.支持配置文件

什么时候使用

1.类或者对象依赖与别的类或者对象

2.依赖关系比较复杂或者需要进一步提前

3.想利用DI

4.想管理对象实例生命周期

5.希望在运行时改变依赖关系

6.希望在Web 应用程序回复时可以缓存或者持久化依赖关系