[英]Simple Injector: Automatic constructor injection recursion
I am trying to understand how automatic constructor injection is done in SimpleInjector.NET. 我试图了解如何在SimpleInjector.NET中完成自动构造函数注入。 My working source code is from the Code Project article (v1.5.0.12199).
我的工作源代码来自“代码项目”文章(v1.5.0.12199)。
I have looked at the Container's GetInstance)() code and also the InstanceProducer's GetInstance() code but I don't see any recursive calls anywhere. 我查看了Container的GetInstance)()代码以及InstanceProducer的GetInstance()代码,但是在任何地方都看不到任何递归调用。
Can someone point out where the recursion for automatic constructor injection happens? 有人可以指出构造函数自动注入的递归发生在哪里吗?
A lot has changes in the container from version v1.5 to the current v2.5 framework. 从版本v1.5到当前的v2.5框架,容器进行了大量更改。 How things are exactly done in the old version I can't recall, but this is what happens in the current v2.5 version (and things might of course change in the future, since they are implementation details).
我不记得在旧版本中是如何完成确切的事情的,但这就是当前v2.5版本中发生的事情(将来,事情可能会发生变化,因为它们是实现细节)。
If you want to look at the method where this happens, you need to go to the private BuildConstructorParameters
method of the Registration
class (note again, I'm talking about the v2.5 source code here). 如果要查看发生这种情况的方法,则需要转到
Registration
类的私有BuildConstructorParameters
方法(再次注意,我在这里谈论的是v2.5源代码)。 This method calls Type.GetParameters
and iterates them and asks the configured IConstructorInjectionBehavior
type for the expression for the parameter. 此方法调用
Type.GetParameters
并对其进行迭代,并向配置的IConstructorInjectionBehavior
类型询问参数的表达式。 The DefaultConstructorInjectionBehavior
will call Container.GetRegistration
to get the proper InstanceProducer
for that parameter and that closes the loop. DefaultConstructorInjectionBehavior
将调用Container.GetRegistration
为该参数获取正确的InstanceProducer
,从而关闭循环。
So the complete stack trace will be something like this (in top down order): 因此,完整的堆栈跟踪将是这样的(从上到下的顺序):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.