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

com.cerner.beadledom.guice.dynamicbindings.DynamicBindingProviderImpl Maven / Gradle / Ivy

There is a newer version: 4.1.2
Show newest version
package com.cerner.beadledom.guice.dynamicbindings;

import com.cerner.beadledom.guice.BindingAnnotations;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import java.lang.annotation.Annotation;

/**
 * Internal implementation of {@link DynamicBindingProvider}.
 *
 * @author John Leacox
 * @since 1.2
 */
class DynamicBindingProviderImpl implements DynamicBindingProvider {
  private Injector injector;
  private TypeLiteral type;

  DynamicBindingProviderImpl(TypeLiteral type) {
    this.type = type;
  }

  @Inject
  void init(Injector injector) {
    this.injector = injector;
  }

  @Override
  public synchronized T get(Class bindingAnnotation) {
    BindingAnnotations.checkIsBindingAnnotation(bindingAnnotation);

    Key key = Key.get(type, bindingAnnotation);
    return injector.getInstance(key);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy