Skip to content

Migration guide from dependency_injector #65

Answered by lesnik512
JobaDiniz asked this question in Q&A
Discussion options

You must be logged in to vote

@JobaDiniz It possible to do this now like this:

import typing

import fastapi
from starlette import status
from starlette.testclient import TestClient

from tests import container
from that_depends import BaseContainer, container_context, fetch_context_item, providers


async def init_di_context(request: fastapi.Request) -> typing.AsyncIterator[None]:
    async with container_context({"request": request}):
        yield


app = fastapi.FastAPI(dependencies=[fastapi.Depends(init_di_context)])


class DIContainer(BaseContainer):
    context_request = providers.Factory(
        lambda: fetch_context_item("request"),
    )


@app.get("/")
async def read_root(
    context_request: typing.Anno…

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@lesnik512
Comment options

Answer selected by lesnik512
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #60 on August 11, 2024 06:32.