-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
63 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## wireup_init_fastapi_integration | ||
::: wireup.integration.fastapi_integration.wireup_init_fastapi_integration | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Dependency injection for FastAPI (all versions) is available via the first-party integration wireup provides, available in | ||
`wireup.integration.fastapi_integration`. | ||
|
||
|
||
**Features:** | ||
|
||
* Automatically decorate Flask views and blueprints where the container is being used. | ||
* Eliminates the need for `@container.autowire` in views. | ||
* Views without container references will not be decorated. | ||
* Services **must** be annotated with `Wire()`. | ||
* Can: Mix FastAPI dependencies and Wireup in views | ||
* Can: Autowire any FastAPI target with `@container.autowire`. | ||
* Cannot: Use FastAPI dependencies in Wireup service objects. | ||
|
||
!!! tip | ||
As FastAPI does not have a fixed configuration mechanism, you need to expose | ||
any configuration objects to the container using one of the two options: | ||
|
||
* By dumping all values in the parameter bag | ||
* Registering the configuration object as a service using a factory function. | ||
|
||
## Examples | ||
|
||
```python | ||
|
||
app = FastAPI() | ||
|
||
@app.get("/random") | ||
async def target( | ||
# Wire annotation tells wireup that this argument should be injected | ||
random_service: Annotated[RandomService, Wire()], | ||
is_debug: Annotated[bool, Wire(param="env.debug")], | ||
lucky_number: Annotated[int, Depends(get_lucky_number)] | ||
): | ||
return { | ||
"number": random_service.get_random(), | ||
"lucky_number": lucky_number, | ||
"is_debug": is_debug, | ||
} | ||
|
||
# Initialize the integration. | ||
# Must be called after all views have been registered. | ||
# Pass to service_modules a list of top-level modules where your services reside. | ||
wireup_init_fastapi_integration(app, service_modules=[services]) | ||
``` | ||
|
||
## Api Reference | ||
|
||
* [fastapi_integration](../class/fastapi_integration.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters