Update what is DI page

This commit is contained in:
Roman Mogylatov 2020-07-18 00:13:56 -04:00
parent 9b94521b96
commit 6aee30ea15
3 changed files with 13 additions and 15 deletions
docs/introduction
examples/di_demo

View File

@ -83,14 +83,12 @@ Let's go through the code of ``example.py``:
.. literalinclude:: ../../examples/di_demo/example.py
:language: python
:linenos:
At some point, things defined above mean, that the code from ``example.py``,
At some point, things defined above mean, that the code from ``example.py``,
could look different, like in ``example_di.py``:
.. literalinclude:: ../../examples/di_demo/example_di.py
:language: python
:linenos:
Best explanation, ever
~~~~~~~~~~~~~~~~~~~~~~

View File

@ -2,16 +2,16 @@
class Service:
"""Some "Service"."""
"""The Service."""
class Client:
"""Some "Client" that uses "Service"."""
"""The Client that uses the Service."""
def __init__(self):
"""Initialize instance."""
self.service = Service() # Service instance is created inside Client
"""Initialize the Client."""
self.service = Service() # The Service is created by the Client
if __name__ == '__main__':
client = Client() # Application creates Client's instance
client = Client() # Application creates the Client

View File

@ -1,18 +1,18 @@
"""The Code, that demonstrates dependency injection pattern."""
"""The Code that demonstrates dependency injection pattern."""
class Service:
"""Some "Service"."""
"""The Service."""
class Client:
"""Some "Client" that uses "Service"."""
"""The Client that uses the Service."""
def __init__(self, service): # Service instance is injected into Client
"""Initialize instance."""
def __init__(self, service): # The Service is injected into the Client
"""Initialize the Client."""
self.service = service
if __name__ == '__main__':
service = Service() # Application creates Service instance
client = Client(service) # and inject Service instance into the Client
service = Service() # Application creates the Service
client = Client(service) # and inject the Service into the Client