Skip to content

Commit

Permalink
Docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
maldoinc committed Sep 10, 2023
1 parent 2685193 commit 28f2f20
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
14 changes: 14 additions & 0 deletions docs/pages/factory_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ def get_user_logs(user: AuthenticatedUser):
...
```

Assume a base class `Notifier` with implementations that define how the notification is sent (IMAP, POP, WebHooks, etc.)
Given a user it is possible to instantiate the correct type of notifier based on user preferences.


```python
@container.register
def get_user_notifier(user: AuthenticatedUser) -> Notifier:
notifier_type = ...

return container.get(notifier_type)
```

When injecting `Notifier` the correct type will be created based on the authenticated user's preferences.

## Links

* [Introduce to an existing project](introduce_to_an_existing_project.md)
3 changes: 1 addition & 2 deletions docs/pages/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# :thread: WireUp

Dependency injection library designed to provide a powerful and flexible way to
manage and inject dependencies across your application,
making it easier to develop, test, and maintain Python codebases.
manage and inject dependencies making it easier to develop, test, and maintain Python codebases.

## Key features

Expand Down
11 changes: 11 additions & 0 deletions docs/pages/manual_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ on each.
container.register_all_in_module(app.service, "*Service")
```

## Interfaces

Even though It's not possible to automatically register abstract types and implementation using qualifiers.
Manual registration is still possible.

```python
container.abstract(FooBase)
container.register(FooBar, qualifier="bar")
container.register(FooBaz, qualifier="baz")
```

## Manually wiring parameters

Given that parameters can't be resolved from type annotations alone, the `container.wire` method offers two shortcuts
Expand Down
6 changes: 3 additions & 3 deletions docs/pages/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DbService:
@container.register
@dataclass
class UserRepository:
db: DbService # Dependencies may also depend on other dependencies. (2)!
db: DbService# Dependencies may also depend on other dependencies. (2)!
```

1. The decorators do not modify the classes in any way and only serve to collect metadata. This behavior can make
Expand All @@ -45,9 +45,8 @@ class UserRepository:
**3. Inject**

```python
# Decorate all methods where the library must perform injection.
@app.route("/greet/<str:name>")
@container.autowire
@container.autowire#(2)!
# Classes are automatically injected based on annotated type.
# Parameters will be located based on the hint given in their default value.
# Unknown arguments will not be processed.
Expand All @@ -57,6 +56,7 @@ def greet(name: str, user_repository: UserRepository, env: str = wire(param="env

1. We know that this will be used in conjunction with many other libraries, so WireUp will not throw on unknown
parameters in order to let other decorators to do their job.
2. Decorate all methods where the library must perform injection.

**Installation**

Expand Down
5 changes: 4 additions & 1 deletion docs/pages/stylesheets/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ dd, dd p {

.card {
flex: 0 1 calc(50% - 5px);
background-color: #ffffff;
border: 1px solid #ddd;
border-radius: 3px;
padding: 20px;
}

body[data-md-color-scheme="slate"] .card {
border: 1px solid var(--md-default-fg-color--lightest) !important;
}

.card-title{
font-weight: bold;
display: flex;
Expand Down

0 comments on commit 28f2f20

Please sign in to comment.