2021-02-19 01:49:39 +03:00
|
|
|
"""Containers module."""
|
|
|
|
|
|
|
|
from dependency_injector import containers, providers
|
|
|
|
|
|
|
|
from .services import ConfigService
|
|
|
|
|
|
|
|
|
|
|
|
class Core(containers.DeclarativeContainer):
|
2021-09-30 22:03:19 +03:00
|
|
|
config = providers.Configuration("config")
|
2021-02-19 01:49:39 +03:00
|
|
|
|
|
|
|
|
|
|
|
class Storage(containers.DeclarativeContainer):
|
2021-09-30 22:03:19 +03:00
|
|
|
queue = providers.Singleton(lambda: "Some storage")
|
2021-02-19 01:49:39 +03:00
|
|
|
|
|
|
|
|
|
|
|
class Adapter(containers.DeclarativeContainer):
|
|
|
|
core = providers.DependenciesContainer(config=providers.Configuration())
|
|
|
|
tinydb = providers.Singleton(
|
2021-09-30 22:03:19 +03:00
|
|
|
lambda db_path: f"DB Path=[{db_path}]",
|
2021-02-19 01:49:39 +03:00
|
|
|
db_path=core.config.default.db_path,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class Repository(containers.DeclarativeContainer):
|
|
|
|
adapter = providers.DependenciesContainer()
|
|
|
|
storage = providers.DependenciesContainer()
|
|
|
|
site = providers.Singleton(
|
2021-09-30 22:03:19 +03:00
|
|
|
lambda adapter, queue: f"Adapter=[{adapter}], queue=[{queue}]",
|
2021-02-19 01:49:39 +03:00
|
|
|
adapter=adapter.tinydb,
|
|
|
|
queue=storage.queue,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class Service(containers.DeclarativeContainer):
|
|
|
|
core = providers.DependenciesContainer()
|
|
|
|
config = providers.Singleton(ConfigService, core.config.provider)
|
|
|
|
|
|
|
|
|
|
|
|
class Application(containers.DeclarativeContainer):
|
|
|
|
|
|
|
|
core = providers.Container(Core)
|
|
|
|
storage = providers.Container(Storage)
|
|
|
|
adapter = providers.Container(Adapter, core=core)
|
|
|
|
repository = providers.Container(Repository, adapter=adapter, storage=storage)
|
|
|
|
service = providers.Container(Service, core=core)
|