mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-02-17 03:50:56 +03:00
Update single and multiple containers example
This commit is contained in:
parent
1aa2be4491
commit
35864f476f
|
@ -3,7 +3,7 @@
|
||||||
from .containers import Application
|
from .containers import Application
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
application = Application()
|
application = Application()
|
||||||
config = application.service.config()
|
config = application.service.config()
|
||||||
config.build()
|
config.build()
|
||||||
|
|
|
@ -6,17 +6,17 @@ from .services import ConfigService
|
||||||
|
|
||||||
|
|
||||||
class Core(containers.DeclarativeContainer):
|
class Core(containers.DeclarativeContainer):
|
||||||
config = providers.Configuration('config')
|
config = providers.Configuration("config")
|
||||||
|
|
||||||
|
|
||||||
class Storage(containers.DeclarativeContainer):
|
class Storage(containers.DeclarativeContainer):
|
||||||
queue = providers.Singleton(lambda: 'Some storage')
|
queue = providers.Singleton(lambda: "Some storage")
|
||||||
|
|
||||||
|
|
||||||
class Adapter(containers.DeclarativeContainer):
|
class Adapter(containers.DeclarativeContainer):
|
||||||
core = providers.DependenciesContainer(config=providers.Configuration())
|
core = providers.DependenciesContainer(config=providers.Configuration())
|
||||||
tinydb = providers.Singleton(
|
tinydb = providers.Singleton(
|
||||||
lambda db_path: f'DB Path=[{db_path}]',
|
lambda db_path: f"DB Path=[{db_path}]",
|
||||||
db_path=core.config.default.db_path,
|
db_path=core.config.default.db_path,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class Repository(containers.DeclarativeContainer):
|
||||||
adapter = providers.DependenciesContainer()
|
adapter = providers.DependenciesContainer()
|
||||||
storage = providers.DependenciesContainer()
|
storage = providers.DependenciesContainer()
|
||||||
site = providers.Singleton(
|
site = providers.Singleton(
|
||||||
lambda adapter, queue: f'Adapter=[{adapter}], queue=[{queue}]',
|
lambda adapter, queue: f"Adapter=[{adapter}], queue=[{queue}]",
|
||||||
adapter=adapter.tinydb,
|
adapter=adapter.tinydb,
|
||||||
queue=storage.queue,
|
queue=storage.queue,
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,4 +6,4 @@ class ConfigService:
|
||||||
self._config = config
|
self._config = config
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
self._config.from_dict({'default': {'db_path': '~/test'}})
|
self._config.from_dict({"default": {"db_path": "~/test"}})
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from dependency_injector.wiring import inject, Provide
|
from dependency_injector.wiring import Provide, inject
|
||||||
|
|
||||||
from .services import UserService, AuthService, PhotoService
|
from .services import UserService, AuthService, PhotoService
|
||||||
from .containers import Application
|
from .containers import Application
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from dependency_injector.wiring import inject, Provide
|
from dependency_injector.wiring import Provide, inject
|
||||||
|
|
||||||
from .services import UserService, AuthService, PhotoService
|
from .services import UserService, AuthService, PhotoService
|
||||||
from .containers import Container
|
from .containers import Container
|
||||||
|
|
Loading…
Reference in New Issue
Block a user