Demo of Manual Dependency Injection

This Maven project shows DI (dependency injection), without using any DI framework.  So if you try to run Main.main, you get NullPointerExceptions for each Controller object, as no implementation was injected.

Instead, we will manually inject the object references by using the JUnit framework.  So instead of running “java com.wpollock.dimanual.Main”, you would run the JUnit test.

Three different DI methods are shown: property injection (which usually uses reflection but not in this example), setter injection, and constructor injection.  Constructor injection is considered the best practice.

Maven POM:

Source Code:

JUnit5 Test Code:

Maven-Generated Website:

DIDemoManual Project Download (zip):