All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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 internalFactory;

    public ProviderToInternalFactoryAdapter(InjectorImpl injector,
                                            InternalFactory 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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy