New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate WebApiRequestLifestyle #331
Comments
dotnetjunkie, since WebApiRequestLifestyle is pratically ExecutionContextScopeLifestyle, and since (according to the documentation) ExecutionContextScopeLifestyle can be used across threads, how does Simple Injecter differentiate between the threads handling two separate yet simultaneous calls to the same container? What I mean is, if I have scoped service A, with an integer property X, and Thread 10 which is servicing Request 1, changes the value of property X to, let's say '2'. Will Thread 11, which is servicing Request 2, also see the change in property X on service A? |
That's not exactly accurate. The scope of an The logical flow of control will be related to a request. This means that a scope will be related to the request as well, independent of how many threads are involved in the execution of that thread.
This asynchronous scoping ensures that scopes are isolated within a request. The same thread 10 can be used to serve both request A and request B, but when such thread will resolve from the container, it will do so within the context of the scope for that request. This means that both requests get their own independent value for X. |
Ah, that's where I was missing a bit of important information: the threads have to be related for the So while we're at it, can the Btw, I agree with the deprecation of the |
To visualize the effect the best, just look at how the private static AsyncLocal<int> local = new AsyncLocal<int>();
public static Task DoSomething(int x)
{
local.Value = x;
await OtherMethod();
// Now we might run on a different thread
Assert.AreEqual(x, local.Value);
}
The
That's a bit a difficult question, but in general I would advise the following:
In other words, in case you are calling services within a In case the |
The WebApi integration quick-start still generates |
The Web API integration package contains the
WebApiRequestLifestyle
, but this lifestyle is a mere wrapper around theExecutionContextScopeLifestyle
(in fact, it's a sub class). It adds no extra behavior. The only difference between theWebApiRequestLifestyle
andExecutionContextScopeLifestyle
is its name. This has been done because the nameWebApiRequestLifestyle
is much more obvious for developers creating a Web API application and since the nameExecutionContextScopeLifestyle
is a bit confusing.In v4 however we are renaming
ExecutionContextScopeLifestyle
toAsyncScopedLifestyle
. Since this name is much more obvious, there is not much reason to keep theWebApiRequestLifestyle
around and we should deprecate it. This makes the integration story for Simple Injector much simpler, because there are less scoped lifestyles to choose from.The text was updated successfully, but these errors were encountered: