use of com.google.inject.Scope in project roboguice by roboguice.
the class ScopeBindingProcessor method visit.
@Override
public Boolean visit(ScopeBinding command) {
Scope scope = checkNotNull(command.getScope(), "scope");
Class<? extends Annotation> annotationType = checkNotNull(command.getAnnotationType(), "annotation type");
if (!Annotations.isScopeAnnotation(annotationType)) {
errors.missingScopeAnnotation(annotationType);
// Go ahead and bind anyway so we don't get collateral errors.
}
if (!Annotations.isRetainedAtRuntime(annotationType)) {
errors.missingRuntimeRetention(annotationType);
// Go ahead and bind anyway so we don't get collateral errors.
}
ScopeBinding existing = injector.state.getScopeBinding(annotationType);
if (existing != null) {
if (!scope.equals(existing.getScope())) {
errors.duplicateScopes(existing, annotationType, scope);
}
} else {
injector.state.putScopeBinding(annotationType, command);
}
return true;
}
use of com.google.inject.Scope in project roboguice by roboguice.
the class Scoping method scope.
/** Scopes an internal factory. */
static <T> InternalFactory<? extends T> scope(Key<T> key, InjectorImpl injector, InternalFactory<? extends T> creator, Object source, Scoping scoping) {
if (scoping.isNoScope()) {
return creator;
}
Scope scope = scoping.getScopeInstance();
Provider<T> scoped = scope.scope(key, new ProviderToInternalFactoryAdapter<T>(injector, creator));
return new InternalFactoryToProviderAdapter<T>(scoped, source);
}
Aggregations