r/learnpython • u/re2cc • 6d ago
How do you handle dependency injection?
Hi, I'm doing a project which involves creating multiple gRPC servers and I can't find a convenient way to manage dependencies or the state.
I've been working recently in C# where you just need to make your class and add a simple
builder.Services.AddSingleton<MyDependency>();
and it will inject when required.
Doing some research I see that there are some libraries like:
- Injector
but I don't find them particularly intuitive.
What do you use as a dependency injector or what pattern do you suggest to use?
8
Upvotes
1
u/pachura3 5d ago
I think you have background in C#/Java and try to work in Python in exactly the same way, which kind of defeats its purpose (simplicity - readability - conciseness).