Skip to content

Instantly share code, notes, and snippets.

@adrienlauer
Created October 4, 2017 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrienlauer/636220b61db509b38f7be0975994dd1e to your computer and use it in GitHub Desktop.
Save adrienlauer/636220b61db509b38f7be0975994dd1e to your computer and use it in GitHub Desktop.
Retrieve instances from SeedStack in any external Guice module
@Install
public class BridgeModule extends AbstractModule {
public void configure() {
requestStaticInjection(SeedStackProvider.class);
}
}
public class ExternalModule extends AbstractModule {
public void configure() {
Key<Repository<Customer, CustomerId>> myRepoKey = Key.get(
new TypeLiteral<Repository<Customer, CustomerId>>() {},
Names.named("someName")
);
bind(myRepoKey).toProvider(new SeedStackProvider<>(myRepoKey));
}
}
public class SeedStackProvider<T> implements Provider<T> {
@Inject
private static Injector injector;
private final Key<T> key;
public SeedStackProvider(Key<T> key) {
this.key = key;
}
public T get() {
return injector.getInstance(key);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment