How Punq dependency injection works
mainPunq is an unintrusive dependency injection library that avoids global state, decorators, and special syntax on arguments.
To use Punq, you must explicitly create a punq.Container at your application's entrypoint. You then register dependencies (either specific instances or classes) with the container and use resolve() to retrieve them. Punq automatically handles recursive dependency injection: if a requested class has dependencies in its __init__ method, Punq will resolve and inject those dependencies automatically.
import punq
# 1. Create the container
container = punq.Container()
# 2. Register dependencies
container.register(BaseService, ConcreteService)
# 3. Resolve dependencies
service = container.resolve(BaseService)