python-dependency-injector/examples/di_demo/example_di.py

19 lines
472 B
Python
Raw Normal View History

"""The Code that demonstrates dependency injection pattern."""
2016-03-29 20:17:12 +03:00
class Service:
"""The Service."""
2016-03-29 20:17:12 +03:00
class Client:
"""The Client that uses the Service."""
2016-03-29 20:17:12 +03:00
def __init__(self, service): # The Service is injected into the Client
"""Initialize the Client."""
2016-03-29 20:17:12 +03:00
self.service = service
if __name__ == '__main__':
service = Service() # Application creates the Service
client = Client(service) # and inject the Service into the Client