python-dependency-injector/examples/miniapps/bundles/run.py
Roman Mogylatov 1c6160e827
Feature/declarative container initialization (#176)
* Add overriding functionality on declarative container initialization

* Update changelog

* Update bundles example
2017-12-24 23:03:13 +02:00

32 lines
790 B
Python

"""Example application - Bundles."""
from dependency_injector import containers
from dependency_injector import providers
from bundles.users import Users
from bundles.photos import Photos
class Core(containers.DeclarativeContainer):
"""Core container."""
pgsql = providers.Singleton(object)
s3 = providers.Singleton(object)
if __name__ == '__main__':
# Initializing containers
core = Core()
users = Users(database=core.pgsql)
photos = Photos(database=core.pgsql, file_storage=core.s3)
# Fetching few users
user_repository = users.user_repository()
user1 = user_repository.get(id=1)
user2 = user_repository.get(id=2)
# Making some checks
assert user1.id == 1
assert user2.id == 2
assert user_repository.db is core.pgsql()