50

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

2 Answers 2

52

Martin Fowler shows it like this:

DI UML

Sign up to request clarification or add additional context in comments.

5 Comments

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)
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 baeldung.com/…
what is assembler here?
@kudlatiger The Assembler is the one creating the proper instance of MovieFinder and then injecting it into the MovieLister.
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?
16

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.