-
Notifications
You must be signed in to change notification settings - Fork 88
Implementation of SessionScope Needed #239
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
Comments
Any update on merging this? |
There's a footgun in the proposed solution, as @tomyou666 points out
This will result in a memory leak. Session storage MUST be cleared after a configurable timeout to prevent that. It might be possible to achieve that using TTLCache from cachetools. That said, I'm not sure if the maintainers of this project are willing to make changes to the API of injector to add an optional
|
In the end it's not my call, but I'm a bit reluctant to make such changes to the API. While it's a pretty small change, it's an addition to a general interface with a pretty specific use-case. I think it makes more sense to implement it in some way closer to |
As stated before, I also think that the need for cleanup is another solid argument against implementing this in the Injector core. Have you investigated the option to create the |
Uh oh!
There was an error while loading. Please reload this page.
I am using this library in my personal development project with FastAPI + SQLAlchemy. For instance, when creating an application that handles a database, I often find the need for a SessionScope to manage instances on a per-session basis.
Here are the requirements I have for SessionScope:
I attempted to implement SessionScope by inheriting from the Scope class, following the example in docs/scopes.rst. However, I found that inheriting from the Scope class alone doesn't allow managing with session_id effectively.
I believe this is structurally challenging in Injector, Provider, and Scope classes to propagate a unique ID like session_id (or scope_id). If I'm wrong, I'd like your opinion.
So, I propose the following solutions:
example)
Regarding 3., I don't know how to destroy the
_context
session at an arbitrary time. Is there a better way to do this as well?The text was updated successfully, but these errors were encountered: