44

How do I show Dependency Injection of an object or class in a UML class diagram?

StarWind0
  • 1,554
  • 2
  • 17
  • 46
Roman
  • 64,384
  • 92
  • 238
  • 332

2 Answers2

47

Martin Fowler shows it like this:

DI UML

Jeremy
  • 22,188
  • 4
  • 68
  • 81
  • 29
    For anyone still curious how this notation is supposed to be interpreted: With the arrow pointing from `A` to `B`, then this means *`A` gets injected with a `B`*. (One could also say *`B` is injected into `A`*)... So with the given example, *`MovieLister` gets injected with a `MovieFinder`*. (One could also say *`MovieFinder` is injected into `MovieLister`*) – Abdull Jan 30 '13 at 15:30
  • 1
    Re: the "assembler" in the diagram. "In the Spring framework, the IoC container is represented by the interface ApplicationContext. The Spring container is responsible for instantiating, configuring and assembling objects known as beans, as well as managing their lifecycle." from https://www.baeldung.com/inversion-control-and-dependency-injection-in-spring – mLstudent33 Apr 15 '19 at 03:44
  • what is assembler here? – kudlatiger Oct 01 '19 at 09:59
  • 1
    @kudlatiger The Assembler is the one creating the proper instance of MovieFinder and then injecting it into the MovieLister. – clapas Feb 14 '20 at 14:33
  • I don't get why the bottom most arrow points from Assembler to MovieLister. Shouldn't the arrow point in the opposite direction? Doesn't MovieLister look up the injected Implementation for MovieFinder at the Assembler when MovieLister gets constructed? – emrich Sep 01 '22 at 09:46
15

You display class dependencies by using a dashed line with a pointed arrow that points from the client model element to the supplier model element.

I think that how you provide the dependencies to the client is irrelevent at the UML level.

Simone
  • 11,655
  • 1
  • 30
  • 43