mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 17:47:02 +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:
|
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
|
:language: python
|
||||||
|
|
||||||
``Car`` **creates** an ``Engine`` during its creation. Really? Does it make
|
``Car`` **creates** an ``Engine`` during its creation. Really? Does it make
|
||||||
more sense then creating an ``Engine`` separatelly and then
|
more sense then creating an ``Engine`` separatelly and then
|
||||||
**put (inject) it into** ``Car`` when ``Car`` is being created?
|
**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
|
: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."""
|
"""The Code, that uses IoC container."""
|
||||||
|
|
||||||
from dependency_injector import catalogs
|
from dependency_injector import catalogs, providers
|
||||||
from dependency_injector import providers
|
|
||||||
|
|
||||||
from ioc_example import Service
|
from ioc_example import Service, Client
|
||||||
from ioc_example import Client
|
|
||||||
|
|
||||||
|
|
||||||
class Components(catalogs.DeclarativeCatalog):
|
class Components(catalogs.DeclarativeCatalog):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user