Wrappers to ensure distributed session loading is done asynchronously as per advice in MS docs.
Note: It looks like currently it's kind of pointless to try and optimize LoadAsync
to only occur where needed (as in my middleware below checking for at least the cookie, or as per suggestions in closed issues to have an attribute that could be sprinkled on controllers/actions) as the standard session middleware always runs CommitAsync
(see here), which in turn checks ISession.IsAvailable
, which calls Load
and ends up doing a sync load... So as far as I can tell, as soon as you've got UseSession()
in your pipeline, bar shortcircuited handling for things like static files, you're going to have this CommitAsync
run, regardless of what your app code is doing (setting or getting values from Session). Still testing if there's something else that avoids the unnecessary load though.
Usage:
// Services setup
services.Configure<OurDistributedSessionSettings>(
Config.GetSection("OurDistributedSes