AsyncExitStackMiddleware
This class provides an ASGI middleware that adds an AsyncExitStack to the request scope, enabling downstream components to manage the lifecycle of asynchronous resources. It ensures that all registered cleanups and context managers are properly closed after the request is processed by wrapping the application call in an asynchronous context manager.
Attributes
| Attribute | Type | Description |
|---|---|---|
| app | ASGIApp | The ASGI application instance that this middleware wraps and delegates calls to. |
| context_name | str = fastapi_middleware_astack | The key name used to store the AsyncExitStack instance within the ASGI scope dictionary. |
Constructor
Signature
def AsyncExitStackMiddleware(
app: ASGIApp,
context_name: str = fastapi_middleware_astack
) - > None
Parameters
| Name | Type | Description |
|---|---|---|
| app | ASGIApp | The ASGI application instance. |
| context_name | str = fastapi_middleware_astack | The key name used to store the AsyncExitStack in the ASGI scope. |
Signature
def AsyncExitStackMiddleware(
app: ASGIApp,
context_name: string = fastapi_middleware_astack
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| app | ASGIApp | The next ASGI application or middleware in the request pipeline to be wrapped. |
| context_name | string = fastapi_middleware_astack | The key name used to store the AsyncExitStack instance within the ASGI scope dictionary. |