Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Per Request Context for my application

Tags:

asp.net-core

I am playing around with the ASP.NET vNext. and I was wondering how to create my own context per request.

In older versions I would create a singleton and store it in HttpContext.Current.Items.

The idea is that I want to load some data at the beginning of the request that should be available through the entire request.

like image 801
Patrick Evers Avatar asked Jan 23 '26 07:01

Patrick Evers


1 Answers

You can achieve the same with HttpContext Items. You would write a middleware like this one and you can handle your stuff inside the Invoke method.

like image 81
tugberk Avatar answered Jan 26 '26 01:01

tugberk