Open serialseb opened 6 years ago
Thanks @serialseb, we should think about moving way from checking the container and just not fail if a duplicate is added. Newer fast DI frameworks don't allow you to add to the container once have read from it, an example is Simple Injector, I also think the new asp.net DI the same.
Well, we have two ways. For containers that support scoping, it doesn't matter cause you register the per-request dependency instances as singletons in the hosting api, for IComm, IRequest etc. For those not supporting it, I don't know what we can do. We can flow per request dependencies in an asynclocal, and pass the containers a Func
Moved from openrasta/openrasta-core#51
In DependencyManager.cs we have this little "test and set" code:
If two threads does the HasDependency() check simultaneous and both of them get "false" then both will try to AddDependency - and one of them fails (depending on the chosen DI container). The Castle container throws an exception when inserting something that exists already.
Here is a stack trace "proof":