python-dependency-injector/examples/ioc_di_demos/ioc_example.py

19 lines
489 B
Python
Raw Normal View History

"""The Code, that follows inversion of control principle."""
2016-03-29 20:17:12 +03:00
class Service(object):
"""Some "Service"."""
class Client(object):
"""Some "Client" that uses "Service"."""
def __init__(self, service): # Service instance is injected in Client
"""Initializer."""
self.service = service
if __name__ == '__main__':
2016-03-30 11:45:41 +03:00
service = Service() # Application creates Service instance
client = Client(service) # and inject Service instance into the Client