Dependency Injection/ Singleton management

Hi,

I’m a longtime software engineer but new to python and backend. I’m wondering how developers are currently handling singletons (examples: database connection, rag index connection) in Langgraph, specifically Langgraph Platform.

I am trying to follow SOLID principles and have some sort of dependency injection, which I see is possible in python for example with FastAPI Depends().

If it’s not some dependency management system, how can I safely and in a production-friendly way, avoid global singletons? Are global singletons safe? Not sure what the implications if the langgraph platform instance is horizontally scaled.

Thanks

Hi @sameer, did you come up with a good solution? I feel like I must be missing something because LangGraph just does not seem to have a good solution for this…

Ya lifespan events that you set on entry and never modify outside of the lifespan

Hi @SpyMachine unfortunately no not really. I did see your thread on reddit and that LangChain Team @sydney-runkle posted Reddit - The heart of the internet
However my experience with Runtime Context has been very poor so far, I halted my migration from RunnableConfig until they iron out the kinks. And like you, I’m not clear on if we can have non serializable objects in there, and how in LangGraph Platform, how we can initialize things that would go into RuntimeContext from a FastAPI lifecycle event for example.
I don’t find the documentation sufficient or complete here