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

View File

@ -83,14 +83,12 @@ Let's go through the code of ``example.py``:
.. literalinclude:: ../../examples/di_demo/example.py .. literalinclude:: ../../examples/di_demo/example.py
:language: python :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``: could look different, like in ``example_di.py``:
.. literalinclude:: ../../examples/di_demo/example_di.py .. literalinclude:: ../../examples/di_demo/example_di.py
:language: python :language: python
:linenos:
Best explanation, ever Best explanation, ever
~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~

View File

@ -2,16 +2,16 @@
class Service: class Service:
"""Some "Service".""" """The Service."""
class Client: class Client:
"""Some "Client" that uses "Service".""" """The Client that uses the Service."""
def __init__(self): def __init__(self):
"""Initialize instance.""" """Initialize the Client."""
self.service = Service() # Service instance is created inside Client self.service = Service() # The Service is created by the Client
if __name__ == '__main__': 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: class Service:
"""Some "Service".""" """The Service."""
class Client: class Client:
"""Some "Client" that uses "Service".""" """The Client that uses the Service."""
def __init__(self, service): # Service instance is injected into Client def __init__(self, service): # The Service is injected into the Client
"""Initialize instance.""" """Initialize the Client."""
self.service = service self.service = service
if __name__ == '__main__': if __name__ == '__main__':
service = Service() # Application creates Service instance service = Service() # Application creates the Service
client = Client(service) # and inject Service instance into the Client client = Client(service) # and inject the Service into the Client