Skip to content

Tijs-2/CoffeeApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CoffeeApp

Example showing multiple modules for the Coffee App

Heater has ...

@ContextModule(name="coffee-heater")

Pump has ...

@ContextModule(name = "coffee-pump", dependsOn = "coffee-heater")

... and with Thermosiphon, a Heater is injected and that comes from the heater module

@Singleton
class Thermosiphon implements Pump {

  private final Heater heater;

  Thermosiphon(Heater heater) {
    this.heater = heater;
  }

Main has ...

@ContextModule(name = "coffee-main", dependsOn = {"coffee-pump", "coffee-heater"})

... and CoffeeMaker which as dependencies provided from pump and heater

@Singleton
public class CoffeeMaker {

  private final Heater heater;
  private final Pump pump;

  public CoffeeMaker(Heater heater, Pump pump) {
    this.heater = heater;
    this.pump = pump;
  }
  ...

Module ordering

The order that the modules are "wired" in DI is determined based on the @ContextModule dependsOn and provides. We can see the ordering in the logs:

Running coffee.app.main.CoffeeMakerTest
22:49:07.836 [main] DEBUG io.dinject.BootContext - building context with modules [coffee-heater, coffee-pump, coffee-main]

... so we see the coffee-heater module is wired first, followed by coffee-pump and then coffee-main

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages