跳转至

注入标记(InjectionMarker)

symphra_container.types.InjectionMarker

注入标记类.

用于标记函数参数应该被容器注入.

示例:

>>> from symphra_container import Container, Injected
>>> container = Container()
>>> def my_function(service: UserService = Injected):
...     # service 会被容器自动注入
...     pass
Source code in src/symphra_container/types.py
class InjectionMarker:
    """注入标记类.

    用于标记函数参数应该被容器注入.

    Examples:
        >>> from symphra_container import Container, Injected
        >>> container = Container()
        >>> def my_function(service: UserService = Injected):
        ...     # service 会被容器自动注入
        ...     pass
    """

    def __init__(self) -> None:
        """初始化注入标记."""

    def __repr__(self) -> str:
        """返回字符串表示."""
        return "Injected"

__init__()

初始化注入标记.

源代码位于: src/symphra_container/types.py
def __init__(self) -> None:
    """初始化注入标记."""

__repr__()

返回字符串表示.

源代码位于: src/symphra_container/types.py
def __repr__(self) -> str:
    """返回字符串表示."""
    return "Injected"