mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 17:47:02 +03:00
Update IoC and DI demos
This commit is contained in:
parent
83bbbd2be7
commit
b2d5819da7
|
@ -10,7 +10,7 @@ class Car(object):
|
|||
|
||||
def __init__(self):
|
||||
"""Initializer."""
|
||||
self.engine = Engine()
|
||||
self.engine = Engine() # Engine is a "hardcoded" dependency
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -10,7 +10,7 @@ class Car(object):
|
|||
|
||||
def __init__(self, engine):
|
||||
"""Initializer."""
|
||||
self.engine = engine
|
||||
self.engine = engine # Engine is an "injected" dependency
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
"""Example of inversion of control container for Car & Engine example."""
|
||||
|
||||
from dependency_injector import catalogs
|
||||
from dependency_injector import containers
|
||||
from dependency_injector import providers
|
||||
|
||||
from car_engine_ioc import Car
|
||||
from car_engine_ioc import Engine
|
||||
|
||||
|
||||
class Components(catalogs.DeclarativeCatalog):
|
||||
"""Catalog of component providers."""
|
||||
class Components(containers.DeclarativeContainer):
|
||||
"""IoC container of component providers."""
|
||||
|
||||
engine = providers.Factory(Engine)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user