类com.google.inject.Scope源码实例Demo

下面列出了怎么用com.google.inject.Scope的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: n4js   文件: MultipleSingletonPluginUITest.java
private boolean isSingleton(Binding<?> b) {
	return b.acceptScopingVisitor(new DefaultBindingScopingVisitor<Boolean>() {
		@Override
		public Boolean visitEagerSingleton() {
			return Boolean.TRUE;
		}

		@Override
		public Boolean visitScope(Scope scope) {
			return Scopes.SINGLETON.equals(scope);
		}

		@Override
		protected Boolean visitOther() {
			return Boolean.FALSE;
		}
	});
}
 
源代码2 项目: dropwizard-guicey   文件: GuiceScopingVisitor.java
@Override
public Class<? extends Annotation> visitScope(final Scope scope) {
    Class<? extends Annotation> res = null;
    if (scope == Scopes.SINGLETON) {
        res = javax.inject.Singleton.class;
    }
    if (scope == Scopes.NO_SCOPE) {
        res = Prototype.class;
    }
    if (scope == ServletScopes.REQUEST) {
        res = RequestScoped.class;
    }
    if (scope == ServletScopes.SESSION) {
        res = SessionScoped.class;
    }
    // not supporting custom scopes
    return res;
}
 
@Test
public void test_lazy_singleton_scope_is_singleton() throws Exception {
    final Scope scope1 = LazySingletonScope.get();
    final Scope scope2 = LazySingletonScope.get();

    assertSame(scope1, scope2);
}
 
@Override
protected void configure() {
    final Scope lazySingletonScope = LazySingletonScope.get();
    bindScope(LazySingleton.class, lazySingletonScope);
}
 
源代码5 项目: ProjectAres   文件: AbstractBindingBuilder.java
@Override
public void in(Scope scope) {
    applyScoping(Scoping.forInstance(scope));
}
 
源代码6 项目: dremio-oss   文件: GuiceServiceModule.java
@Override
protected void configure() {
  binder().bindListener(Matchers.any(), new ProvisionListener() {
    @Override
    public <T> void onProvision(ProvisionInvocation<T> provision) {
      final Binding<T> binding = provision.getBinding();
      logger.debug("provisioning {}", binding.getKey().getTypeLiteral());

      final T provisioned = provision.provision();

      if (provisioned != null && Service.class.isAssignableFrom(provisioned.getClass())) {
        final AtomicBoolean start = new AtomicBoolean(false);
        binding.acceptScopingVisitor(new DefaultBindingScopingVisitor<T>() {
          @Override
          public T visitEagerSingleton() {
            start.set(true);
            return super.visitEagerSingleton();
          }

          @Override
          public T visitScope(Scope scope) {
            if (scope instanceof SingletonScope) {
              start.set(true);
            }
            return super.visitScope(scope);
          }
        });

        if (start.get()) {
          serviceList.push(binding.getKey().getTypeLiteral().getRawType());
          try {
            logger.debug("starting {}", binding.getKey().getTypeLiteral());
            ((Service) provisioned).start();
          } catch (Exception e) {
            throwIfUnchecked(e);
            throw new RuntimeException(e);
          }
        }
      }
    }
  });
}
 
源代码7 项目: seed   文件: LifecycleMatcher.java
@Override
public Boolean visitScope(Scope scope) {
    return scope == Scopes.SINGLETON;
}
 
源代码8 项目: saga-lib   文件: SagaLibModule.java
/**
 * Perform binding to interface only if implementation type is not null.
 */
private <T> void bindIfNotNull(final Class<T> interfaceType, @Nullable final Class<? extends T> implementationType, final Scope scope) {
    if (implementationType != null) {
        bind(interfaceType).to(implementationType).in(scope);
    }
}
 
源代码9 项目: js-dossier   文件: ConfigModule.java
ConfigModule(Flags flags, Config config, Path outputDir, Scope documentationScope) {
  this.flags = flags;
  this.config = config;
  this.outputDir = outputDir;
  this.documentationScope = documentationScope;
}
 
/**
 * Returns the LazySingletonScope
 *
 * @return the LazySingletonScope
 */
public static Scope get() {
    return instance;
}
 
源代码11 项目: ProjectAres   文件: Binders.java
default void installIn(Scope scope, Module... modules) { installIn(Scoping.forInstance(scope), modules); } 
 类所在包
 同包方法