python-dependency-injector/examples/providers/factory.py

20 lines
339 B
Python

"""`Factory` provider example."""
from dependency_injector import containers, providers
class User:
...
class Container(containers.DeclarativeContainer):
user_factory = providers.Factory(User)
if __name__ == "__main__":
container = Container()
user1 = container.user_factory()
user2 = container.user_factory()