public interface GreetingService {
void sayHello();
}
public class SimpleGreetingService implements GreetingService {
public void sayHello() {
System.out.println("Hello, Airframe!");
}
}
@Module
public class GreetingModule {
@Provides
public GreetingService provideGreetingService() {
return new SimpleGreetingService();
}
}
@Module
public class MainModule {
@Provides
public GreetingService provideGreetingService() {
return new SimpleGreetingService();
}
public static void main(String[] args) {
Injector injector = Injector.builder()
.modules(GreetingModule.class)
.build();
GreetingService greetingService = injector.getInstance(GreetingService.class);
greetingService.sayHello();
}
}