-
Notifications
You must be signed in to change notification settings - Fork 6
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
14 changed files
with
210 additions
and
54 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
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 @@ | ||
WireUp relies on various kind of type annotations or hints to be able to autowire dependencies. | ||
When it is not possible to automatically locate a given dependency the argument must be annotated | ||
with additional metadata. | ||
|
||
## When do you need to provide annotations. | ||
|
||
Not needed when injecting: | ||
|
||
* Services | ||
* Injecting an interface which has only one implementing service | ||
|
||
Annotations required when injecting: | ||
|
||
* Parameters | ||
* Parameter expressions | ||
* Injecting an interface which has multiple implementing services. | ||
|
||
## Annotation types | ||
|
||
Wireup supports two types of annotations. Using Python's `Annotated` or by using default values. | ||
|
||
### Annotated | ||
|
||
This is the preferred method for Python 3.9+ and moving forward. It is also recommended to | ||
backport this using `typing_extensions` for Python 3.8. | ||
|
||
|
||
```python | ||
@container.autowire | ||
def target( | ||
env: Annotated[str, Wire(param="env_name")], | ||
logs_cache_dir: Annotated[str, Wire(expr="${cache_dir}/logs")] | ||
): | ||
... | ||
``` | ||
|
||
### Default values | ||
|
||
This relies on the use of default values to inject parameters. Anything that can be passed to `Annotated` may also | ||
be used here. | ||
|
||
```python | ||
@container.autowire | ||
def target( | ||
env: str = wire(param="env_name"), | ||
logs_cache_dir: str = wire(expr="${cache_dir}/logs") | ||
): | ||
... | ||
``` |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.