Created
March 19, 2012 17:18
-
-
Save jdewind/2119886 to your computer and use it in GitHub Desktop.
Session Scoped EventBus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Module | |
- (void)configure { | |
bind(EventBus.class).toProvider(new Provider<EventBus>() { | |
AtomicInteger counter = new AtomicInteger(); | |
public EventBus get() { | |
return new EventBus("Event Bus Session #" + counter.incrementAndGet()); | |
} | |
}).in(SessionScoped.class); | |
requestInjection(InjectorHolder.class); | |
} | |
public class InjectorHolder { | |
@Inject private static Injector injector; | |
public static Injector getInjector() { | |
return injector; | |
} | |
} | |
public class EventBusTypeListener implements TypeListener { | |
public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) { | |
encounter.register(new InjectionListener<I>() { | |
public void afterInjection(I injectee) { | |
InjectorHolder.getInjector().getInstance(EventBus.class).register(injectee); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment