mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-27 12:04:00 +03:00
7d160cb4a5
* Update main example * Updating wiring module * Update wiring test case name * Implement string imports for wiring * Update example * Refactor implementation * Update front example * Fix a typo in README * Update wiring docs * Update single container example * Update multiple containers example * Update quotes in multiple containers example * Update quotes in single container example * Update decoupled-packages example * Update single and multiple containers example * Update quotes * Update fastapi+redis example * Update resource docs * Update quotes in CLI tutorial * Update CLI application (movie lister) tutorial * Update monitoring daemon example * Update python version in asyncio daemon example * Update asyncio daemon tutorial * Update quotes in wiring docs * Update wiring docs
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
"""Containers module."""
|
|
|
|
from dependency_injector import containers, providers
|
|
|
|
from .services import ConfigService
|
|
|
|
|
|
class Core(containers.DeclarativeContainer):
|
|
config = providers.Configuration("config")
|
|
|
|
|
|
class Storage(containers.DeclarativeContainer):
|
|
queue = providers.Singleton(lambda: "Some storage")
|
|
|
|
|
|
class Adapter(containers.DeclarativeContainer):
|
|
core = providers.DependenciesContainer(config=providers.Configuration())
|
|
tinydb = providers.Singleton(
|
|
lambda db_path: f"DB Path=[{db_path}]",
|
|
db_path=core.config.default.db_path,
|
|
)
|
|
|
|
|
|
class Repository(containers.DeclarativeContainer):
|
|
adapter = providers.DependenciesContainer()
|
|
storage = providers.DependenciesContainer()
|
|
site = providers.Singleton(
|
|
lambda adapter, queue: f"Adapter=[{adapter}], queue=[{queue}]",
|
|
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)
|