-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoffeeApp.java
More file actions
41 lines (31 loc) · 1010 Bytes
/
CoffeeApp.java
File metadata and controls
41 lines (31 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package coded.dependency.injection.example.dagger2;
import coded.dependency.injection.Dependency;
import coded.dependency.injection.Dependent;
import coded.dependency.injection.Injector;
public class CoffeeApp {
public static class CoffeeShop implements Dependent {
CoffeeMaker maker = new Dependency<>(this, CoffeeMaker.class).get();
CoffeeLogger logger = new Dependency<>(this, CoffeeLogger.class).get();
CoffeeMaker maker() {
return maker;
}
CoffeeLogger logger() {
return logger;
}
}
public static void main(String[] args) {
CoffeeShop coffeeShop = Injector.getContext("coffee")
.defineConstruction(CoffeeShop.class, CoffeeShop::new)
.defineConstruction(Heater.class, ElectricHeater::new)
.defineConstruction(Pump.class, Thermosiphon::new)
.makeBeans(CoffeeShop.class)
.getBean(CoffeeShop.class);
Injector.getContext("coffee")
.print();
coffeeShop.maker()
.brew();
coffeeShop.logger()
.logs()
.forEach(log -> System.out.println(log));
}
}