Use Root scope when current is null (fixes #646)#670
Use Root scope when current is null (fixes #646)#670ltines wants to merge 4 commits intocastleproject:masterfrom
Conversation
|
I still ask to check for our pr #668 that will fix this and also add support for .NET 8 keyed services. If it is possible could you check code of pr #668 to verify if this fixes null scope in your situation? I'm asking because the support for .NET 8 branch is opened from a long time and I'd like it to be closed if possible (we are in production with that version using a private package source and I'd really like to move again on supported nuget packages) |
|
@alkampfergit i had a quick look, but need to read a lot about semantics (especially keyed / not keyed). I would like to implement it using named instances in Castle so we don't have to introduce new concepts. |
|
Remember that if you are moving to dependency injection version 8.0.0 without keyed service support the adapter does not works . The problem presents when any library starts using keyed service and new resolution semantic, so you got weird error. |
jonorossi
left a comment
There was a problem hiding this comment.
Could you add at least one unit test for this change.
| set => current.Value = value; | ||
| } | ||
|
|
||
| internal static ExtensionContainerScopeBase TryCurrent => current.Value; |
There was a problem hiding this comment.
TryCurrent is a strange name, it's not a function. Any reason not to just name it Current and just document that is can return null?
Fixes #646 by using Root scope when current scope in
ExtensionContainerScopeCache.currentisnull. This can happen whenWindsorScopedServiceProvideris called from a new thread (or rather different async context).In this situation
ForcedScopeuses the original root scope. It also restores it asExtensionContainerScopeCache.currenton dispose.The only case that I haven't figured out is when resolving directly via
IWindsorContainer(and not throughIServiceProvider) on a new thread.ExtensionContainerScopeAccessor.GetScopestill throws "No scope available"