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

推荐订阅源

V
Visual Studio Blog
C
Cisco Blogs
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Scott Helme
Scott Helme
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
M
MIT News - Artificial intelligence
L
LINUX DO - 热门话题
I
InfoQ
GbyAI
GbyAI
NISL@THU
NISL@THU
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Engineering at Meta
Engineering at Meta
H
Hackread – Cybersecurity News, Data Breaches, AI and More
TaoSecurity Blog
TaoSecurity Blog
Simon Willison's Weblog
Simon Willison's Weblog
A
About on SuperTechFans
Spread Privacy
Spread Privacy
月光博客
月光博客
W
WeLiveSecurity
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
有赞技术团队
有赞技术团队
Security Latest
Security Latest
人人都是产品经理
人人都是产品经理
PCI Perspectives
PCI Perspectives
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Microsoft Azure Blog
Microsoft Azure Blog
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
T
Troy Hunt's Blog
Martin Fowler
Martin Fowler
The Hacker News
The Hacker News
T
Tor Project blog
C
CERT Recently Published Vulnerability Notes
Apple Machine Learning Research
Apple Machine Learning Research
Stack Overflow Blog
Stack Overflow Blog
K
Kaspersky official blog
Cloudbric
Cloudbric
H
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
D
DataBreaches.Net
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Tenable Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - Franky
L
LINUX DO - 最新话题
MyScale Blog
MyScale Blog

博客园 - Inrie

[原创]MongoDB、HandlerSocket和MySQL性能测试及其结果分析 [原创]HandlerSocket系列(三):性能及其性能优化 [原创]HandlerSocket系列(二):架构、特点及其应用场景 [原创]HandlerSocket系列(一):由来 SD2.0 2009大会一些感想 在Windows Server 2008集群上做Sql Server 2008集群 解决Azure Project中使用Asp.net MVC RC会让VS崩溃的补丁 [译]剖析ASP.Net MVC Application 让VS 2008也可以用Mobile Web Form 几个不错的WCF Tools ADO.NET Entity Framework Beta3的一些问题 善待你的眼睛-使用微软专为程序员设计的Consolas字体 [推荐]ASP.NET 应用程序的扩展策略 [翻译+推荐]你需要知道的:WCF、WF、ADO.NET SyncServices和ClickOnce 如何发布Ado.net Entity Framework EDM Unity Application Block 1.0系列文章 Unity Application Block 1.0系列(7): Lifetime Managers Unity Application Block 1.0系列(5): 使用BuildUp让已存在对象实例也支持依赖注入 Unity Application Block 1.0系列(4): 方法调用注入(Method Call Injection )
Unity Application Block 1.0系列(6): 杜绝循环引用
Inrie · 2008-04-18 · via 博客园 - Inrie

public class Class1
{
    
public Class1(Class2 test2)
    {
        ..
    }
}
public class Class2
{
    
public Class2(Class1 test1)  
    {
        
    }
}

通过Unity容器装载Class1时,会做Constructor Injection,由于Class1依赖于Class2,所以会先去装载Class2。在装载Class2时同样也会做Constructor Injection,由于Class2又依赖于Class1,所以会再去装载Class1......这样一直持续装载下去,就成了一个死循环,跳不出来。

2. 通过Constructor Injection生成的对象作为自身构造器的参数直接看例子:

public class Class1
{
    
public Class1(Class1 test1)
  {  }
}

3. 通过method call injection生成的对象互相引用

直接看例子:

public class Class1
{
    [InjectionMethod]
    
public void Method1()
    {
        Method2();
    }

    [InjectionMethod]

public void Method2()
    {
        Method1();
    }
}


4.通过property(setter) injection生成的对象互相引用

直接看例子:

public class Class1
{
    [Dependency]
    
public string Propert1
    {
        
get
        {
            
return Propert2;
        }
    }

    [Dependency]

public string Propert2
    {
        
get
        {
            
return Propert1;
        }
    }
}

作者:Inrie (洪晓军)
出处:http://www.cnblogs.com/inrie