Search in sources :

Example 11 with Scope

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;
}
Also used : Scope(com.google.inject.Scope) ScopeBinding(com.google.inject.spi.ScopeBinding)

Example 12 with Scope

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);
}
Also used : Scope(com.google.inject.Scope)

Aggregations

Scope (com.google.inject.Scope)12 Provider (com.google.inject.Provider)7 AbstractModule (com.google.inject.AbstractModule)6 Key (com.google.inject.Key)6 Injector (com.google.inject.Injector)4 Module (com.google.inject.Module)4 PrivateModule (com.google.inject.PrivateModule)4 Date (java.util.Date)4 ImmutableList (com.google.common.collect.ImmutableList)2 CreationException (com.google.inject.CreationException)2 Guice.createInjector (com.google.inject.Guice.createInjector)2 OutOfScopeException (com.google.inject.OutOfScopeException)2 ProvisionException (com.google.inject.ProvisionException)2 ScopeBinding (com.google.inject.spi.ScopeBinding)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Binding (com.google.inject.Binding)1 BindingImpl (com.google.inject.internal.BindingImpl)1 ProviderMethod (com.google.inject.internal.ProviderMethod)1 Scoping (com.google.inject.internal.Scoping)1