@Override public Injector createChildInjector(Module... modules) { return delegateInjector.createChildInjector(modules); }
@Override public Injector createChildInjector(Iterable<? extends Module> modules) { return delegateInjector.createChildInjector(modules); }
public Injector createChildInjector(Injector injector) { Injector childInjector = injector.createChildInjector(modules); Injectors.cleanCaches(childInjector); // in ES, we always create all instances as if they are eager singletons // this allows for considerable memory savings (no need to store construction info) as well as cycles ((InjectorImpl) childInjector).readOnlyAllSingletons(); return childInjector; } }
/** * 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); }