Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injecting with typing.Annotated #693

Open
maintain0404 opened this issue Apr 7, 2023 · 1 comment · May be fixed by #721
Open

Injecting with typing.Annotated #693

maintain0404 opened this issue Apr 7, 2023 · 1 comment · May be fixed by #721

Comments

@maintain0404
Copy link

Hello. Thank you for building and maintaining awesome project.

FastAPI recently announced a new feature called Annotated. link
Currently, dependency-injector is not compatible with this feature. How about modify it to be compatible?
Like fastapi, wiring with Annotated can make several benefits like re-using, more compatibility with type checkers and so on.

See sample code following.

from typing import Annotated
from dependency_injector.containers import DeclarativeContainer
from dependency_injector.providers import Factory
from dependency_injector.wiring import inject


class Service:
    ...


class Container(DeclarativeContainer):
    service = Factory(Service)


WiredService = Annotated[Service, Provide[Container.service]]


@inject
def to_be_injected(service: WiredService):
    ...

I already made it for using at my personal work.
If PR is welcome, I'll made PR with the code I've wrote and other work.

@maintain0404 maintain0404 changed the title Support typing.Annotated Injecting with typing.Annotated Apr 7, 2023
@fadedDexofan
Copy link

Please make PR or share how you implemented this

@maintain0404 maintain0404 linked a pull request Jul 9, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants