You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After #960 (which was caused by #946 ) activation stack depth increased in case resolving types registered in root scope from grandchild scope. In #960 reuse of ExternalComponentRegistration was removed so child, grandchild, great-grandchild ... scopes will have own ExternalComponentRegistration instances for parent scopes registrations. Now Activation stack depth = Type dependency depth * scope hierarchy depth,
which causes DependencyResolutionException with MaxDepthExceeded earlier than before.
Steps to Reproduce
Consider we have a type A registered in root scope. Type A has 16-depth dependency. If we try to resolve type A from a grandchild scope well get next exception.
Each dependent type repeats 3 times. If we tried to resolve type A from great-grandchild we would see that every dependent type repeats 4 times and so on.
Short term, the Autofac.Core.Resolving.CircularDependencyDetector.MaxResolveDepth field is private, but static and intentionally so you can use reflection to tweak it. Increase that as needed. It is also intentionally not exposed in the public API because we reserve the right to change it, but that should get you over the hump.
If you're using Autofac 4.9.1 as indicated, you should upgrade. Autofac 5 was released six months ago and we're on 5.2.0 right now.
Longer term, we're working on a version 6.0.0 release with a huge internals overhaul. Circular dependency detection has been improved and, where possible, we use the actual remaining stack depth before stack overflow rather than having a hard limit.
I'm going to close this issue for now since we have, to the best of our abilities, addressed it both short and long term. If you continue having the issue after upgrading to v6 when it's released, we can reopen and revisit it.
Describe the Bug
After #960 (which was caused by #946 ) activation stack depth increased in case resolving types registered in
root
scope fromgrandchild
scope. In #960 reuse ofExternalComponentRegistration
was removed sochild
,grandchild
,great-grandchild
... scopes will have ownExternalComponentRegistration
instances for parent scopes registrations. NowActivation stack depth
=Type dependency depth
*scope hierarchy depth
,which causes
DependencyResolutionException
withMaxDepthExceeded
earlier than before.Steps to Reproduce
Consider we have a type
A
registered inroot
scope. TypeA
has 16-depth dependency. If we try to resolve typeA
from agrandchild
scope well get next exception.Each dependent type repeats 3 times. If we tried to resolve type
A
fromgreat-grandchild
we would see that every dependent type repeats 4 times and so on.Sample test with deep scopes hierarchy:
Expected Behavior
Activation stack depth not to depend on scopes hierarchy depth so much.
Dependency Versions
Faced the issue on 4.9.1
The text was updated successfully, but these errors were encountered: