static void installFactories(Linker linker) {
linker.install(VisitHandler.class, new Factory<VisitHandler>() {
Factory<Logger> loggerFactory;
Factory<Counter> counterFactory;
@Override public void link(Linker linker) {
counterFactory = linker.factoryFor(Counter.class);
loggerFactory = linker.factoryFor(Logger.class);
}
@Override public VisitHandler get() {
return new VisitHandler(counterFactory.get(), loggerFactory.get());
}
});
linker.install(Logger.class, new Factory<Logger>() {
Factory<PrintStream> printStreamFactory;
@Override public void link(Linker linker) {
printStreamFactory = linker.factoryFor(PrintStream.class);
}
@Override public Logger get() {
return new Logger(printStreamFactory.get());
}
});
linker.install(PrintStream.class, ValueFactory.of(System.out));
linker.install(Counter.class, SingletonFactory.of(new Factory<Counter>() {
@Override public Counter get() {
return new Counter();
}
}));
}