Skip to content

Dependency injection

Sven Kubiak edited this page Nov 23, 2018 · 2 revisions

For dependency injections mangoo I/O uses Google Guice.

The simplest use case for dependency injection is to inject a class as a member variable.

@Inject
private MyClass myClass;

You can also grap an instance of a class using the static function of the Application class.

MyClass myClass = Application.getInstance(MyClass.class);

The most recommended approach is to use injection through the constructor.

private Foo foo;

@Inject
public MyClass(Foo foo) {
    this.foo = Objects.requireNonNull(foo);
}