💡 add depends example

This commit is contained in:
yanyongyu 2021-11-21 17:09:31 +08:00
parent 9a29966e2d
commit 23c237cb2a
2 changed files with 29 additions and 0 deletions

View File

@ -26,3 +26,18 @@ sidebarDepth: 0
* `use_cache: bool = True`: 是否使用缓存。默认为 `True`
```python
def depend_func() -> Any:
return ...
def depend_gen_func():
try:
yield ...
finally:
...
async def handler(param_name: Any = Depends(depend_func), gen: Any = Depends(depend_gen_func)):
...
```

View File

@ -203,5 +203,19 @@ def Depends(dependency: Optional[T_Handler] = None,
* ``dependency: Optional[Callable[..., Any]] = None``: 依赖函数默认为参数的类型注释
* ``use_cache: bool = True``: 是否使用缓存默认为 ``True``
.. code-block:: python
def depend_func() -> Any:
return ...
def depend_gen_func():
try:
yield ...
finally:
...
async def handler(param_name: Any = Depends(depend_func), gen: Any = Depends(depend_gen_func)):
...
"""
return DependsWrapper(dependency=dependency, use_cache=use_cache)