mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Update introduction docs and examples
This commit is contained in:
parent
136b562a81
commit
56a597e0a6
|
@ -86,12 +86,12 @@ Example
|
|||
|
||||
Let's go through next example:
|
||||
|
||||
.. literalinclude:: ../../../examples/ioc_demo/car_engine_1.py
|
||||
.. literalinclude:: ../../../examples/ioc_di_demo/car_engine_1.py
|
||||
:language: python
|
||||
|
||||
``Car`` **creates** an ``Engine`` during its creation. Really? Does it make
|
||||
more sense then creating an ``Engine`` separatelly and then
|
||||
**put (inject) it into** ``Car`` when ``Car`` is being created?
|
||||
|
||||
.. literalinclude:: ../../../examples/ioc_demo/car_engine_2.py
|
||||
.. literalinclude:: ../../../examples/ioc_di_demo/car_engine_2.py
|
||||
:language: python
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
"""Car & Engine example 1."""
|
||||
|
||||
|
||||
class Engine(object):
|
||||
"""Example engine."""
|
||||
|
||||
|
||||
class Car(object):
|
||||
"""Example car."""
|
||||
|
||||
def __init__(self):
|
||||
"""Initializer."""
|
||||
self.engine = Engine()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
car = Car()
|
||||
assert car.engine is not None
|
|
@ -1,18 +0,0 @@
|
|||
"""Car & Engine example 2."""
|
||||
|
||||
|
||||
class Engine(object):
|
||||
"""Example engine."""
|
||||
|
||||
|
||||
class Car(object):
|
||||
"""Example car."""
|
||||
|
||||
def __init__(self, engine):
|
||||
"""Initializer."""
|
||||
self.engine = engine
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
car = Car(Engine())
|
||||
assert car.engine is not None
|
|
@ -1,10 +1,8 @@
|
|||
"""The Code, that uses IoC container."""
|
||||
|
||||
from dependency_injector import catalogs
|
||||
from dependency_injector import providers
|
||||
from dependency_injector import catalogs, providers
|
||||
|
||||
from ioc_example import Service
|
||||
from ioc_example import Client
|
||||
from ioc_example import Service, Client
|
||||
|
||||
|
||||
class Components(catalogs.DeclarativeCatalog):
|
||||
|
|
Loading…
Reference in New Issue
Block a user