@Override public <T> Binding<T> getBinding(Class<T> type) { return this.delegateInjector.getBinding(type); }
private boolean isBound(Injector injector, Key<?> key) { // This method is particularly lame - we really need an API that can test // for any binding, implicit or explicit try { return injector.getBinding(key) != null; } catch (ConfigurationException e) { return false; } }
@Override public <T> Binding<T> getBinding(Key<T> key) { return this.delegateInjector.getBinding(key); }
/** * Creates a child injector that binds the args, and returns the binding for the method's result. */ public Binding<?> getBindingFromNewInjector(final Method method, final Object[] args) { checkState(injector != null, "Factories.create() factories cannot be used until they're initialized by Guice."); final Key<?> returnType = returnTypesByMethod.get(method); Module assistedModule = new AbstractModule() { @Override @SuppressWarnings("unchecked") // raw keys are necessary for the args array and return value protected void configure() { Binder binder = binder().withSource(method); int p = 0; for (Key<?> paramKey : paramTypes.get(method)) { // Wrap in a Provider to cover null, and to prevent Guice from injecting the parameter binder.bind((Key) paramKey).toProvider(Providers.of(args[p++])); } if (producedType != null && !returnType.equals(producedType)) { binder.bind(returnType).to((Key) producedType); } else { binder.bind(returnType); } } }; Injector forCreate = injector.createChildInjector(assistedModule); return forCreate.getBinding(returnType); }
@Override protected ShardIndexVersion shardOperation(GetIndicesVersionRequest request, ShardRouting shardRouting) throws IOException { IndexService indexService = indicesService.indexServiceSafe(shardRouting.getIndex()); IndexShard indexShard = indexService.shardSafe(shardRouting.id()); // Get the IndexVersionShardService associated to this shard Injector injector = indexService.shardInjectorSafe(shardRouting.id()); IndexVersionShardService indexVersionService = injector.getBinding(IndexVersionShardService.class).getProvider().get(); long version = indexVersionService.getVersion(); return new ShardIndexVersion(indexShard.routingEntry(), version); }