Skip to content

Injection to Annotated on FastAPI Router (python 3.11) #767

Closed
@Modif93

Description

@Modif93

I'm using Dependency injector on my FastAPI Project.

currently using FastAPI

while Injecting some packages on FastAPI + SQLAlchemy + DI Project, for example

@router.get("/users")
@inject
def get_users(
        user_service: UserService = Depends(Provide[Container.user_service])
) -> List[UserModel] :
    some..codes..

I inject dependencies with non-annotated style codes.

can I do it with annotated style, like for example

userService = Annotated[UserService, Depends(Provide[Container.user_service])]

@router.get("/users")
@inject
def get_users(user_service: userService) -> List[UserModel] :
    some..codes..

It doesn't works well, with following errors.

AttributeError: 'Provide' object has no attribute 'get_all'

Think it finds dependency from Provide.

is there any way to use annotated style like above?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions