The method you have a problem with is just 1 line:
/// <summary>
/// Marks the begin of a scope and therefore creates the scope data storage.
/// </summary>
/// <param name="scopeStorage">The scope storage to use. This scopestorage is passed in by the di scope started.</param>
internal static void BeginScope(DependencyInjectionInfoStorage scopeStorage)
{
// push the scope onto the stack
_scopeStorages.Push(scopeStorage);
}
This variable is a ThreadStatic variable. This variable is set in the Init() method of the class, so for every thread a new instance is created.
I.o.w.: I have a hard time imagining how that stack could possibly be null. Especially because our tests run fine...
You also posted the wrong unittest. You posted the clinic test, while the error occurs in: MainBusComponentConstructorTest
(edit) The thing is that the DependencyInjectionProvider is a singleton, and it gets initialized by static ctors. This already should have been done when an entity class is instantiated. Apparently this isn't done in your case, the DependencyInjectionProvider's CTor (the non-static one) is never ran, which means DependencyInjectionInfoProviderSingleton is never used in code. THAT means that an entity has never been instantiated.
This could be a small bug though. In our tests, the singleton already is there, so we don't run into this issue. Could you, for testing, first request the DependencyInjectionInfoProviderSingleton.GetInstance() in your test, and then do the code you want to run in your test? That would make the stack get initialized.
AddInjectionInfo simply stores data in internal buckets in the scope till the init is done. This thus means that can't call into the callchain you posted.
The initially error you posted in the topicstart is I think indeed an edge case when nothing has been done and a scope is created -> the thread specific stack hasn't been created.
I'll try to see if I can repro it without any injection info set so it's close to your situation.
(edit) btw your classes are internal inside another class, this requires different type specifications. Make the classes normal classes (so not nested classes)