Skip to content
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

Support app state from ASGI Lifespan Protocol #2352

Open
vytas7 opened this issue Oct 3, 2024 · 0 comments
Open

Support app state from ASGI Lifespan Protocol #2352

vytas7 opened this issue Oct 3, 2024 · 0 comments

Comments

@vytas7
Copy link
Member

vytas7 commented Oct 3, 2024

The ASGI Lifespan Protocol offers Lifespan State (if the app server supports it):

Applications often want to persist data from the lifespan cycle to request/response handling. For example, a database connection can be established in the lifespan cycle and persisted to the request/response cycle. The scope["state"] namespace provides a place to store these sorts of things. The server will ensure that a shallow copy of the namespace is passed into each subsequent request/response call into the application. Since the server manages the application lifespan and often the event loop as well this ensures that the application is always accessing the database connection (or other stored object) that corresponds to the right event loop and lifecycle, without using context variables, global mutable state or having to worry about references to stale/closed connections.

In Falcon apps, another alternative is simply storing data inside resource or middleware attributes, but it might be still nice to make use of this state, e.g., to interact with generic middleware etc.

@vytas7 vytas7 added this to the Version 4.x milestone Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant