Is HttpContext.Current.Items["SameKey"] unique for each call made to the ASP.NET WebApi?

asp.net asp.net-mvc asp.net-web-api entity-framework-6 httpcontext

Question

I am using Angular2 as a client and for server side its ASP.NET WebAPI + EF6. My DbContext is being shared for multiple DB operation within the same WebApi request. To share DbContext among multiple DB Operations, i am keeping DbContext in HttpContext.Current.Items["SameKey"].

So will it be unqiue on each WebApi call?

1
1
8/14/2017 3:25:27 AM

Accepted Answer

It's guaranteed to be unique. The HttpContext.Current.Items is only valid for a single request and when the request is sent back to a browser, its data will be flushed out automatically.

Please visit the following link for more information:

Hope this will help you

1
8/14/2017 4:33:44 AM

Popular Answer

Although I'd recommend you to use an IoC module (e.g. Ninject) to manage the context's lifecycle - Yes HttpContext.Current.Items[] is guaranteed to be unique and persisted for the duration of the http request.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow