python-dependency-injector/examples/providers/singleton.py
Roman Mogylatov 6eff213a68
Migrate to alabaster (#264)
* Add bootstrap and remove created at from ghnav-flask app

* Update readme

* Add logo to the docs

* Update key features description

* Update README

* Change headers of API docs

* Add alabaster theme config

* Update docs index

* Add tutorials section

* Update what is DI page

* Update DI in Python page

* Update tutorials index page

* Update provider docs

* Update container docs

* Update examples docs
2020-07-18 00:40:14 -04:00

20 lines
542 B
Python

"""`Singleton` providers example."""
import collections
import dependency_injector.providers as providers
UsersService = collections.namedtuple('UsersService', [])
# Singleton provider creates new instance of specified class on first call
# and returns same instance on every next call.
users_service_provider = providers.Singleton(UsersService)
# Retrieving several UserService objects:
users_service1 = users_service_provider()
users_service2 = users_service_provider()
# Making some asserts:
assert users_service1 is users_service2