Session Middleware Transient Session Store #48807
-
I have a general question about the session middleware. I'm wondering why the session store service is added as transient in src/Middleware/Session/src/SessionServiceCollectionExtensions.cs. My understanding is that when the session middleware is created it will create a session store and use that same one throughout it's lifetime which is the lifetime of the app. Is the transient session store essentially being used as a singleton since the session middleware that uses it is a singleton? Thank you in advance for any help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes. It's registered as transient, because if any other code would require an |
Beta Was this translation helpful? Give feedback.
Yes.
It's registered as transient, because if any other code would require an
ISessionStore
so that another instance is returned.If that registration would be as singleton, than the same instance is returned, which may lead to overriding the content in the store. So to prevent latent and hard to diagnose bugs, it's registered as transient.