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

17 lines
326 B
Python
Raw Normal View History

"""`Singleton` provider example."""
from dependency_injector import providers
2016-06-08 17:46:40 +03:00
class UserService:
...
user_service_provider = providers.Singleton(UserService)
if __name__ == '__main__':
user_service1 = user_service_provider()
user_service2 = user_service_provider()
assert user_service1 is user_service2