Package com.google.inject

Examples of com.google.inject.Scope


    if (scoping.isNoScope()) {
      return creator;
    }

    Scope scope = scoping.getScopeInstance();

    try {
      SingletonScope.singletonCreationPerRootInjectorLock.set(injector.state.singletonCreationLock());
      Provider<T> scoped
          = scope.scope(key, new ProviderToInternalFactoryAdapter<T>(injector, creator));
      return new InternalFactoryToProviderAdapter<T>(scoped, source);
    } finally {
      SingletonScope.singletonCreationPerRootInjectorLock.set(null);
    }
  }
View Full Code Here


            @Override public <T> Void visit(Binding<T> binding) {
              if (!overriddenKeys.remove(binding.getKey())) {
                super.visit(binding);

                // Record when a scope instance is used in a binding
                Scope scope = getScopeInstanceOrNull(binding);
                if (scope != null) {
                  scopeInstancesInUse.put(scope, binding.getSource());
                }
              }
View Full Code Here

  ScopeBindingProcessor(Errors errors) {
    super(errors);
  }

  @Override public Boolean visit(ScopeBinding command) {
    Scope scope = command.getScope();
    Class<? extends Annotation> annotationType = command.getAnnotationType();

    if (!Annotations.isScopeAnnotation(annotationType)) {
      errors.withSource(annotationType).missingScopeAnnotation();
      // Go ahead and bind anyway so we don't get collateral errors.
    }

    if (!Annotations.isRetainedAtRuntime(annotationType)) {
      errors.withSource(annotationType)
          .missingRuntimeRetention(command.getSource());
      // Go ahead and bind anyway so we don't get collateral errors.
    }

    Scope existing = injector.state.getScope(checkNotNull(annotationType, "annotation type"));
    if (existing != null) {
      errors.duplicateScopes(existing, annotationType, scope);
    } else {
      injector.state.putAnnotation(annotationType, checkNotNull(scope, "scope"));
    }
View Full Code Here

    if (scoping.isNoScope()) {
      return creator;
    }

    Scope scope = scoping.getScopeInstance();

    Provider<T> scoped
        = scope.scope(key, new ProviderToInternalFactoryAdapter<T>(injector, creator));
    return new InternalFactoryToProviderAdapter<T>(
        Initializables.<Provider<? extends T>>of(scoped));
  }
View Full Code Here

    Class<? extends Annotation> scopeAnnotation = scoping.getScopeAnnotation();
    if (scopeAnnotation == null) {
      return scoping;
    }

    Scope scope = injector.state.getScope(scopeAnnotation);
    if (scope != null) {
      return forInstance(scope);
    }

    errors.scopeNotFound(scopeAnnotation);
View Full Code Here

  public void putBinding(Key<?> key, BindingImpl<?> binding) {
    explicitBindingsMutable.put(key, binding);
  }

  public Scope getScope(Class<? extends Annotation> annotationType) {
    Scope scope = scopes.get(annotationType);
    return scope != null ? scope : parent.getScope(annotationType);
  }
View Full Code Here

            if (scoping != null) {
                scopeAnnotation = scoping.getScopeAnnotation();

                // TODO not sure why we need this hack???
                if (scopeAnnotation == null) {
                    Scope scope = scoping.getScopeInstance();
                    if (scope instanceof HasScopeAnnotation) {
                        HasScopeAnnotation hasScopeAnnotation = (HasScopeAnnotation) scope;
                        scopeAnnotation = hasScopeAnnotation
                                .getScopeAnnotation();
                    }
View Full Code Here

            @Override public <T> void writeBind(Binder binder, final Binding<T> binding) {
              if (!overriddenKeys.remove(binding.getKey())) {
                super.writeBind(binder, binding);

                // Record when a scope instance is used in a binding
                Scope scope = getScopeInstanceOrNull(binding);
                if (scope != null) {
                  scopeInstancesInUse.put(scope, binding.getSource());
                }
              }
            }
View Full Code Here

  public void putBinding(Key<?> key, BindingImpl<?> binding) {
    explicitBindingsMutable.put(key, binding);
  }

  public Scope getScope(Class<? extends Annotation> annotationType) {
    Scope scope = scopes.get(annotationType);
    return scope != null ? scope : parent.getScope(annotationType);
  }
View Full Code Here

public class RequestScopeModule extends AbstractModule
{
   @Override
   protected void configure()
   {
      bindScope(RequestScoped.class, new Scope()
      {
         @Override
         public <T> Provider<T> scope(final Key<T> key, final Provider<T> creator)
         {
            return new Provider<T>()
View Full Code Here

TOP

Related Classes of com.google.inject.Scope

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.