Skip to content

Is that-depends possible to support inject almost everywhere without wiring? #40

Answered by rumbarum
rumbarum asked this question in Q&A
Discussion options

You must be logged in to vote

@lesnik512
Thank you for your answer.

This is my use case of inject something directly. I could wrap it by something callable and inject it as args. But this is much simpler. So I applied this pattern when necessary.

session: async_scoped_session = Provide["session"]

class SQLAlchemyMiddleware:
    def __init__(self, app: ASGIApp) -> None:
        self.app = app

    async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
        session_id = str(uuid4())
        context = set_session_context(session_id=session_id)
        try:
            await self.app(scope, receive, send)
        except Exception as e:
            raise e
        finally:
            await session.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
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
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #39 on June 21, 2024 09:02.