解决与依赖注入循环依赖 [英] resolving circular dependencies with dependency injection

查看:415
本文介绍了解决与依赖注入循环依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过上建议使用依赖注入解决.NET组件之间循环依赖各网站的文章。这可能会解决生成错误,但它不是真正解决循环依赖,是吗?对我来说,似乎依然在架构的逻辑错误。我是疯了还是做其他人都同意1)这是一个比恒星使用DI,以及2)不恰当的方式来解决循环依赖问题?

I've seen several articles on various websites that propose resolving circular dependencies between .NET assemblies by using dependency injection. This may resolve the build errors but it's not really resolving the circular dependency, is it? To me, there seems to still be a logical error in the architecture. Am I crazy or do others agree 1) this is a less than stellar use of DI, and 2) not the appropriate way to solve circular dependency issues?

推荐答案

如果你有两个对象之间循环依赖,这意味着你需要第三个对象,对其中的两个对象,将取决于,这样它们就不会依赖彼此。下面是一篇文章,说是确切的解决您的问题:

If you have circular dependencies between two objects, it means you need a third object, on which the two objects will depend on, so they won't depend on each other. Here is an article that is the exact solution to your problem:

<一个href=\"http://misko.hevery.com/2008/08/01/circular-dependency-in-constructors-and-dependency-injection/\">http://misko.hevery.com/2008/08/01/circular-dependency-in-constructors-and-dependency-injection/

这篇关于解决与依赖注入循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆