-
Notifications
You must be signed in to change notification settings - Fork 311
Ambient scopes not supported by all DI's #334
Description
So, I'm having a discussion with @dotnetjunkie about implementing a dnx adapter for SimpleInjector (simpleinjector/SimpleInjector#156).
He is not a fan of implementing an abstraction, it is a conforming container anti-pattern. I've argued that if he doesn't create a dnx adapater, SimpleInjector will simply not be a choice with users when doing ASP.NET 5 projects. I believe (and he can correct me if I am wrong) that the ultimate issue comes down to Microsoft's use of ambient scopes.
So, my question is this. When thinking of the common denominator of features between containers, is this actually needed?
Within the ASP.NET stack, are scopes only used within the context of web requests?
What about adding two kinds of scopes:
- Local/ambiant - Requires a reference to the actual
IServiceScopeto resolve a service. This is how the ASP.NET DI currently does it. - Global/non-ambiant - The scope is determined in the container itself. It internally checks HttpContext.Current, or something similar. Maybe it could simply be called a "WebRequestScope", hard coding it, if abstracting it across DI's becomes an issue.
If the ASP.NET request pipeline is currently the only thing using scopes, maybe it can be changed to use global scopes, leaving the local approach in-tact, but just not used. If we do this, SimpleInjector can support web requests, while explicitly declaring that they do not support local scopes. The maintainer of SimpleInjector doesn't have any intention of ever supporting local scopes, and it could simply be a known limitation of using a SimpleInjector dnx adapter. Of course, provided that the core libraries for ASP.NET don't depend on any local scopes. We don't want the SimpleInjector dnx adapter to be broke out-of-the-box.
Any thoughts? I don't think @dotnetjunkie is budging ;) SimpleInjector is one of the fastest DI's, and it will break my heart to see it not supported.