-
I used to use dependency-injector(di) for inject config, complex obj or so on everywhere, As I know, wiring is a key action which reads code and replace initial dummy obj (Provide(...)) to real one(injecting object) before run python process. Will that-depends provide similar usage covering this case without wiring? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello, @rumbarum
service: Service = Provide[Container.service] You can just build dependency anywhere in you code like this
|
Beta Was this translation helpful? Give feedback.
-
@lesnik512 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.remove()
reset_session_context(context=context) Anyway, I will try review your package. |
Beta Was this translation helpful? Give feedback.
@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.