Skip to content

Commit 48f1191

Browse files
committed
Updated README.md.
Signed-off-by: Pavel Kirilin <win10@list.ru>
1 parent 4cf72b5 commit 48f1191

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,39 @@ with graph.sync_ctx(replaced_deps={dependency: replaced}) as ctx:
309309
```
310310

311311
Furthermore, the new dependency can depend on other dependencies. Or you can change type of your dependency, like generator instead of plain return. Everything should work as you would expect it.
312+
313+
## Annotated types
314+
315+
Taskiq dependenices also support dependency injection through Annotated types.
316+
317+
```python
318+
from typing import Annotated
319+
320+
async def my_function(dependency: Annotated[int, Depends(my_func)]):
321+
pass
322+
```
323+
324+
Or you can specify classes
325+
326+
327+
```python
328+
from typing import Annotated
329+
330+
class MyClass:
331+
pass
332+
333+
async def my_function(dependency: Annotated[MyClass, Depends(my_func)]):
334+
pass
335+
```
336+
337+
And, of course you can easily save such type aliases in variables.
338+
339+
```python
340+
from typing import Annotated
341+
342+
DepType = Annotated[int, Depends(my_func)]
343+
344+
def my_function(dependency: DepType):
345+
pass
346+
347+
```

0 commit comments

Comments
 (0)