page_title: Dependency injection
section_title: UML class and sequence diagram
hierarchical_section_title: Dependency injection / Structure / UML class and sequence diagram
caption_attribution_description: English: Dependency Injection UML class and sequence diagram
context_page_description: In software engineering, dependency injection is a technique in which an object receives other objects that it depends on. These other objects are called dependencies. In the typical "using" relationship the receiving object is called a client and the passed object is called a service. The code that passes the service to the client can be many kinds of things and is called the injector. Instead of the client specifying which service it will use, the injector tells the client what service to use. The "injection" refers to the passing of a dependency into the object that would use it.
  The service is made part of the client's state. Passing the service to the client, rather than allowing a client to build or find the service, is the fundamental requirement of the pattern.
  The intent behind dependency injection is to achieve separation of concerns of construction and use of objects. This can increase readability and code reuse.
  Dependency injection is one form of the broader technique of inversion of control. A client who wants to call some services should not have to know how to construct those services.
context_section_description: In the above UML class diagram, the Client class 
  that requires ServiceA and ServiceB objects does not instantiate the ServiceA1 and ServiceB1 classes directly.
  Instead, an Injector class creates the objects and injects them
  into the Client, which makes the Client independent of how the objects are created (which concrete classes are instantiated).
  
  The UML sequence diagram shows the run-time interactions: The Injector object creates the ServiceA1 and ServiceB1 objects.
  Thereafter, the Injector creates the Client object
  and injects the ServiceA1 and ServiceB1 objects.
caption: A sample UML class and sequence diagram for the Dependency Injection design pattern. [35]
exif: {}