mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-03-26 12:54:24 +03:00
Update what is DI page
This commit is contained in:
parent
9b94521b96
commit
6aee30ea15
|
@ -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
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user