<dependency>
<groupId>org.ickenham</groupId>
<artifactId>ickenham-core</artifactId>
<version>1.0.0</version>
</dependency>
@Module
public class MyModule {
@Provides
public MyService myService() {
return new MyServiceImpl();
}
@Provides
public AnotherService anotherService() {
return new AnotherServiceImpl();
}
}
public interface MyService {
void doSomething();
}
public class MyServiceImpl implements MyService {
@Override
public void doSomething() {
System.out.println("Doing something...");
}
}
public interface AnotherService {
void doAnotherThing();
}
public class AnotherServiceImpl implements AnotherService {
@Override
public void doAnotherThing() {
System.out.println("Doing another thing...");
}
}
public class MyApp {
private final MyService myService;
private final AnotherService anotherService;
@Inject
public MyApp(MyService myService, AnotherService anotherService) {
this.myService = myService;
this.anotherService = anotherService;
}
public void run() {
myService.doSomething();
anotherService.doAnotherThing();
}
}
public class Main {
public static void main(String[] args) {
Injector injector = Ickenham.createInjector(new MyModule());
MyApp app = injector.getInstance(MyApp.class);
app.run();
}
}