com.google.inject.internal.ProviderToInternalFactoryAdapter Maven / Gradle / Ivy
package com.google.inject.internal;
import com.google.inject.Provider;
final class ProviderToInternalFactoryAdapter implements Provider {
private final InjectorImpl injector;
private final InternalFactory extends T> internalFactory;
public ProviderToInternalFactoryAdapter(InjectorImpl injector,
InternalFactory extends T> internalFactory) {
this.injector = injector;
this.internalFactory = internalFactory;
}
@Override
public T get() {
try (InternalContext context = injector.enterContext()) {
// Always pretend that we are a linked binding, to support
// scoping implicit bindings. If we are not actually a linked
// binding, we'll fail properly elsewhere in the chain.
return internalFactory.get(context, context.getDependency(), true);
} catch (InternalProvisionException e) {
throw e.toProvisionException();
}
}
/** Exposed for SingletonScope. */
InjectorImpl getInjector() {
return injector;
}
@Override
public String toString() {
return internalFactory.toString();
}
}