[Python] DI (Dependency Injection) container Which one should I use?

Python mock can be easily monkey patched. If you use it, you can unit test without a DI container. However, the body accustomed to DI containers wants IoC, so I decided to look for DI containers.

DI container requirements

I want such a DI container.

Journey to find a DI container

Searching for DI Container on PyPi hits over 10,000. Eh, no way, all this?

152 hits when googled. Still too much!

Let's rely on our predecessors here.

Injector

This is the article that was introduced.

It becomes a constructor injection. It seems that it meets all the requirements, which may be good.

PInjector

This is the article that was introduced.

It looks like a reimplementation of the above Injector. Is the dependency resolved by the argument name instead of the type hint?

autocontainer

Type hints will resolve the dependency. Whether it's a singleton or not is specified in code, not in the decorator. It's simple and may be necessary and sufficient.

Other

It is a library that does not meet the requirements because it has to be registered in the container by itself or it needs to be set separately.

Recommended Posts

[Python] DI (Dependency Injection) container Which one should I use?
DI (Dependency Injection) in Python
Is the priority queue heapq in Competitive Pro (Python)? queue.PriorityQueue? Which one should I use?
% And str.format () in Python. Which one do you use?
curl -I python one liner
Which should I study, R or Python, for data analysis?
Create a DI Container in Python
I made a Docker container to use JUMAN ++, KNP, python (for pyKNP).
After all, what should I use to do type comparisons in Python?
Python 3 multi-process Pool methods should use imap_unordered