Refs: #646 Castle.Windsor.Extension.DepencencyInjection - No Scope Available#664
Closed
AGiorgetti wants to merge 9 commits intocastleproject:masterfrom
Closed
Refs: #646 Castle.Windsor.Extension.DepencencyInjection - No Scope Available#664AGiorgetti wants to merge 9 commits intocastleproject:masterfrom
AGiorgetti wants to merge 9 commits intocastleproject:masterfrom
Conversation
This was referenced Aug 10, 2023
…removed null check on scope cache (AsyncLocal can be null on Threads coming from Threadpool.UnsafeQueueUserWorkItem, having no null check was also the original behavior)
Threadpool.UnsafeQueueUserWorkItem.
this improve resolution of singleton object that might not need a root scope, the windsor container should be enough to resolve singletons
scopes from Threadpool.UnsafeQueueUserWorkItem
93de2df to
b997da0
Compare
Author
|
I am closing this PR because #668 superseeds this one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ExtensionContainerScopeCache.current is an AsyncLocal, AsyncLocal might not be captured in threads originating from Threadpool.UnsafeQueueUserWorkItem.
AspNetCore make heavy use of such threads to optimize performances.
I Added some tests that show supported and unsupported scenarios
I moved the null checks from the AsyncLocal Cache to the scope accessors and improved error messages a bit.
Added an experimental feature to use Castle Windsor standard Singleton lifecycle instead of the custom NetStatic (I believe singletons should always be resolved if you have a container instance whatever the scope is). Enabling it helps me solve singleton resolution issues when the same components are resolved from the IServiceProvider and/or WindsorContainer.
However having "null" for the current scope might be questionable, the Dispose in WindsorScopedServiceProvider rely on that information to correctly cleanup the things (looking at the dotnet DI code, the root scope should be strictly tied to the root service provider).
This behavior might still be good because disposing a ServiceProvider resolved/used in a background thread should not dispose the main container anyway.
I think that more changes should be done like:
There was a previous PR (that I closed) similar to this one with less tests and a fix that didn't worked in some scenario, I clsed that and replaced with this one. I think some more changes can be made and a lot of intermediate commits can be squased.