Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
maldoinc committed Dec 28, 2023
1 parent 504e078 commit 12d495a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 9 deletions.
5 changes: 4 additions & 1 deletion docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ nav:
- Working with Interfaces: interfaces.md
- Manual configuration: manual_configuration.md
- Multiple containers: multiple_containers.md
- Integrations:
- Flask: integrations/flask.md
- FastAPI: integrations/fastapi.md
- Misc:
- Flask Integration: flask_integration.md
- Introduce to an existing project: introduce_to_an_existing_project.md
- Demo application: demo_app.md
- Versioning: versioning.md
Expand All @@ -24,6 +26,7 @@ nav:
- ParameterEnum: class/parameter_enum.md
- InitializationContext: class/initialization_context.md
- flask_integration: class/flask_integration.md
- fastapi_integration: class/fastapi_integration.md
repo_url: https://github.com/maldoinc/wireup
repo_name: maldoinc/wireup
theme:
Expand Down
3 changes: 3 additions & 0 deletions docs/pages/class/fastapi_integration.md
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

5 changes: 2 additions & 3 deletions docs/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
Dependency injection container with a focus on developer experience, type safety and ease of use.

!!! note "New: Dependency injection for Flask"
Simplify usage in Flask applications by using the new [Flask integration](flask_integration.md)!
Simplify usage in Flask applications by using the new [Flask integration](integrations/flask)!

* Automatically inject dependencies on views without having to manually decorate.
* Expose flask application configuration in the container.
* Expose Flask application configuration in the container.

## Key features

Expand Down Expand Up @@ -39,7 +39,6 @@ Dependency injection container with a focus on developer experience, type safety
Interfaces / Abstract classes
</div>
Define abstract types and have the container automatically inject the implementation.
Say goodbye to mocks in your tests!
</div>
<div class="card">
<div class="card-title">
Expand Down
49 changes: 49 additions & 0 deletions docs/pages/integrations/fastapi.md
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)
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ if __name__ == '__main__':
### Using parameter enums

Parameter enums offer a typed way of representing parameters.
See [Parameter Enum documentation for more details](parameters.md#parameter-enums)
See [Parameter Enum documentation for more details](../parameters.md#parameter-enums)

## Api Reference

* [flask_integration](class/flask_integration.md)
* [ParameterEnum](class/parameter_enum.md)
* [flask_integration](../class/flask_integration.md)
* [ParameterEnum](../class/parameter_enum.md)
2 changes: 1 addition & 1 deletion docs/pages/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_posts(post_repository: PostRepository):
```

1. Decorate all methods where the library must perform injection.
Optional when using the [Flask integration](flask_integration.md).
Optional when using the [Flask integration](integrations/flask).


**Installation**
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class PostRepository:
@container.autowire
# Decorate all targets where the library must perform injection, such as views in an Api.
# Services are automatically injected based on annotated type.
# Optional for views when using flask integration.
# Optional for views when using flask integrations.
def get_posts(post_repository: PostRepository):
return post_repository.find_all()
```
Expand Down

0 comments on commit 12d495a

Please sign in to comment.