FastAPI
wireup.integration.fastapi¶
Classes¶
Functions¶
get_app_container(app)
¶
Return the container associated with the given application.
This is the instance created via wireup.create_async_container
.
Use this when you need the container outside of the request context lifecycle.
get_request_container()
¶
When inside a request, returns the scoped container instance handling the current request.
This is what you almost always want.It has all the information the app container has in addition to data specific to the current request.
request_factory()
¶
Provide the current request as a dependency.
setup(container, app, *, class_based_handlers=None, middleware_mode=False)
¶
Integrate Wireup with FastAPI.
Setup performs the following: * Injects dependencies into HTTP and WebSocket routes. * Closes the Wireup container upon app shutdown using the lifespan context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
container |
AsyncContainer
|
An async container created via |
required |
app |
FastAPI
|
The FastAPI application to integrate with. All routes must have been added to the app before this call. |
required |
class_based_handlers |
Optional[Iterable[Type[_ClassBasedHandlersProtocol]]]
|
A list of class-based handlers to register. These classes must have a |
None
|
middleware_mode |
bool
|
If True, the container is exposed in fastapi middleware. Note, for this to work correctly, there should be no more middleware added after the call to this function. For more details, visit: https://maldoinc.github.io/wireup/latest/integrations/fastapi/ |
False
|
websocket_factory()
¶
Provide the current WebSocket as a dependency.