Eclipse Dependency Injection

A java class has a dependency on another class if it uses it as a variable. We want to avoid creating instances of other classes with the new operator because that hard codes the dependency on that class.

Instead we use the @Inject notation, this can inject variables in:


Example from IBM DI Tutorial:

public FrogMan(Vehicle vehicle) {
  this.vehicle = vehicle;

Where Vehicle is an interface.

public FrogMobile(FuelSource fuelSource){
  this.fuelSource = fuelSource;


Example of module from IBM DI Tutorial:

These modules are used by Guice.createInjector to create the injector.

metadata block
see also:
Correspondence about this page

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2022 Martin John Baker - All rights reserved - privacy policy.