Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Commit

Permalink
Allow controllers to be injected too.
Browse files Browse the repository at this point in the history
  • Loading branch information
analytically committed Jun 3, 2013
1 parent 225723d commit ef966ba
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/Global.java
Expand Up @@ -68,6 +68,7 @@ public T create() {
}
}

private Injector injector;
private final List<Module> modules = Lists.newArrayList();

private final List<OnStartListener> onStartListeners = new CopyOnWriteArrayList<OnStartListener>();
Expand Down Expand Up @@ -165,10 +166,15 @@ public void onApplicationStop(Application application) {
});
}

@Override
public <A> A getControllerInstance(Class<A> controllerClass) throws Exception {
return injector.getInstance(controllerClass);
}

@Override
public void onStart(Application app) {
Logger.info("Creating injector with " + modules.size() + " modules.");
Injector injector = Guice.createInjector(Stage.PRODUCTION, modules);
injector = Guice.createInjector(Stage.PRODUCTION, modules);

for (OnStartListener listener : onStartListeners) {
listener.onApplicationStart(app, injector);
Expand Down

0 comments on commit ef966ba

Please sign in to comment.