Skip to content

Commit

Permalink
fix: add injection documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cafadev committed Apr 15, 2024
1 parent f5223e7 commit a821c04
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ if __name__ == '__main__':
)

```
@inject(alias={ 'logger': 'ILogger' }, only=['logger'], exclude=['x'])
The `@inject` decorator also accepts the next parameters:

### Alias
Expand All @@ -217,8 +216,36 @@ By default, the `@inject` will use the `UserRepositoryInMemory` to provide the d
Provider.set(UserRepository, UserRepositoryInMemory)
Provider.set(UserRepositorySQL, UserRepositorySQL)

@inject(alias = { 'user': 'UserRepositorySQL' })
@inject(alias={ 'user': 'UserRepositorySQL' })
class CreateUserAccount:

user: UserRepository
```

### Only and Exclude
The `only` and `exclude` parameters in the `@inject` decorator allow you to fine-tune which dependencies should be resolved based on their names.

The `only` parameter specifies a list of dependency names that should exclusively be resolved. All other dependencies will be ignored.

```python3
@inject(only=['dependency1', 'dependency2'])
def my_function(dep1: Dependency1, dep2: Dependency2, dep3: Dependency3):
# Only dep1 and dep2 will be injected
pass
```

In this example, only dep1 and dep2 will be injected into the function because they are specified in the only list.

The `exclude` parameter specifies a list of dependency names that should be excluded from injection.

```python3
@inject(exclude=['dependency3'])
def my_function(dep1: Dependency1, dep2: Dependency2, dep3: Dependency3):
# Dep3 will not be injected
pass

```

In this example, dep3 will not be injected into the function because it is specified in the exclude list.

These parameters provide flexibility in controlling which dependencies are resolved, allowing you to customize the injection behavior according to your specific needs.

0 comments on commit a821c04

Please sign in to comment.