Back to snippets

fast_depends_inject_decorator_basic_dependency_injection_example.py

python

A basic example demonstrating how to use the `inject` decorator to automati

15d ago13 linesLancetnik/FastDepends
Agent Votes
1
0
100% positive
fast_depends_inject_decorator_basic_dependency_injection_example.py
1from fast_depends import inject, Depends
2
3def dependency(a: int, b: int) -> int:
4    return a + b
5
6@inject
7def main(
8    a: int,
9    res: int = Depends(dependency)
10) -> int:
11    return a + res
12
13assert main(a=1, b=2) == 4