com.google.inject.spi.ScopeBinding Maven / Gradle / Ivy
package com.google.inject.spi;
import com.google.inject.Binder;
import com.google.inject.Scope;
import java.lang.annotation.Annotation;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Registration of a scope annotation with the scope that implements it. Instances are created
* explicitly in a module using {@link com.google.inject.Binder#bindScope(Class, Scope) bindScope()}
* statements:
*
* Scope recordScope = new RecordScope();
* bindScope(RecordScoped.class, new RecordScope());
*
*/
public final class ScopeBinding implements Element {
private final Object source;
private final Class extends Annotation> annotationType;
private final Scope scope;
ScopeBinding(Object source, Class extends Annotation> annotationType, Scope scope) {
this.source = checkNotNull(source, "source");
this.annotationType = checkNotNull(annotationType, "annotationType");
this.scope = checkNotNull(scope, "scope");
}
public Object getSource() {
return source;
}
public Class extends Annotation> getAnnotationType() {
return annotationType;
}
public Scope getScope() {
return scope;
}
public T acceptVisitor(ElementVisitor visitor) {
return visitor.visit(this);
}
public void applyTo(Binder binder) {
binder.withSource(getSource()).bindScope(annotationType, scope);
}
}