本文整理匯總了Java中com.google.inject.Scope類的典型用法代碼示例。如果您正苦於以下問題:Java Scope類的具體用法?Java Scope怎麽用?Java Scope使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Scope類屬於com.google.inject包,在下文中一共展示了Scope類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: applyScoping
import com.google.inject.Scope; //導入依賴的package包/類
protected void applyScoping(Binding<?> binding, final ScopedBindingBuilder scopedBindingBuilder) {
binding.acceptScopingVisitor(new BindingScopingVisitor<Void>() {
public Void visitEagerSingleton() {
if (scopedBindingBuilder != null) {
scopedBindingBuilder.asEagerSingleton();
}
return null;
}
public Void visitScope(Scope scope) {
scopedBindingBuilder.in(scope);
return null;
}
public Void visitScopeAnnotation(Class<? extends Annotation> scopeAnnotation) {
scopedBindingBuilder.in(scopeAnnotation);
return null;
}
public Void visitNoScoping() {
// do nothing
return null;
}
});
}
示例2: scoped
import com.google.inject.Scope; //導入依賴的package包/類
private static String scoped(final Binding<?> binding, final String statement) {
return binding.acceptScopingVisitor(new BindingScopingVisitor<String>() {
@Override
public String visitEagerSingleton() {
if (binding instanceof InstanceBinding<?>) {
return statement;
}
throw new DeguicifierException();
}
@Override
public String visitScope(Scope scope) {
return scopeFieldName(scope) + ".scope(null, " + guicify(statement) + ")";
}
@Override
public String visitScopeAnnotation(Class<? extends Annotation> scopeAnnotation) {
throw new DeguicifierException();
}
@Override
public String visitNoScoping() {
return statement;
}
});
}
示例3: visit
import com.google.inject.Scope; //導入依賴的package包/類
@Override public Boolean visit(ScopeBinding command) {
Scope scope = command.getScope();
Class<? extends Annotation> annotationType = command.getAnnotationType();
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(checkNotNull(annotationType, "annotation type"));
if (existing != null) {
errors.duplicateScopes(existing, annotationType, scope);
} else {
checkNotNull(scope, "scope");
injector.state.putScopeBinding(annotationType, command);
}
return true;
}
示例4: forInstance
import com.google.inject.Scope; //導入依賴的package包/類
public static Scoping forInstance(final Scope scope) {
if (scope == Scopes.SINGLETON) {
return SINGLETON_INSTANCE;
}
return new Scoping() {
@Override public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
return visitor.visitScope(scope);
}
@Override public Scope getScopeInstance() {
return scope;
}
@Override public String toString() {
return scope.toString();
}
@Override public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
scopedBindingBuilder.in(scope);
}
};
}
示例5: testOverrideScopeAnnotation
import com.google.inject.Scope; //導入依賴的package包/類
public void testOverrideScopeAnnotation() {
final Scope scope = new Scope() {
public <T> Provider<T> scope(Key<T> key, Provider<T> unscoped) {
throw new AssertionError("Should not be called");
}
};
final SingleUseScope replacementScope = new SingleUseScope();
Module original = new AbstractModule() {
@Override protected void configure() {
bindScope(TestScopeAnnotation.class, scope);
bind(Date.class).in(TestScopeAnnotation.class);
}
};
Module replacements = new AbstractModule() {
@Override protected void configure() {
bindScope(TestScopeAnnotation.class, replacementScope);
}
};
Injector injector = createInjector(Modules.override(original).with(replacements));
injector.getInstance(Date.class);
assertTrue(replacementScope.used);
}
示例6: visit
import com.google.inject.Scope; //導入依賴的package包/類
@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"));
}
return true;
}
示例7: forInstance
import com.google.inject.Scope; //導入依賴的package包/類
public static Scoping forInstance(final Scope scope) {
if (scope == Scopes.SINGLETON) {
return SINGLETON_INSTANCE;
}
return new Scoping() {
public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
return visitor.visitScope(scope);
}
@Override public Scope getScopeInstance() {
return scope;
}
@Override public String toString() {
return scope.toString();
}
public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
scopedBindingBuilder.in(scope);
}
};
}
示例8: OutOfScopeException
import com.google.inject.Scope; //導入依賴的package包/類
public OutOfScopeException(Scope scope, Key<?> key, Throwable cause)
{
super(String.format(
"Not in scope %s for key %s: caused by %s",
scope, key, cause
), cause);
}
示例9: OutOfScopeException
import com.google.inject.Scope; //導入依賴的package包/類
public OutOfScopeException(Scope scope, Key<?> key, Throwable cause)
{
super(String.format(
"Not in scope %s for key %s: caused by %s",
scope, key, cause
), cause);
}
示例10: bindScopeInstance
import com.google.inject.Scope; //導入依賴的package包/類
@SuppressWarnings({"unchecked"})
public static void bindScopeInstance(Binder binder, Scope scope, Class<? extends Annotation> annotationType)
{
requireNonNull(scope);
binder.bindScope(annotationType, scope);
binder.bind((Class) scope.getClass()).toInstance(scope);
}
示例11: getScopeAnnotation
import com.google.inject.Scope; //導入依賴的package包/類
/**
* Returns the scope annotation for the given binding or null if there is no
* scope
*/
public static Class<? extends Annotation> getScopeAnnotation(
Binding<?> binding) {
Class<? extends Annotation> scopeAnnotation = null;
if (binding instanceof BindingImpl) {
BindingImpl bindingImpl = (BindingImpl) binding;
Scoping scoping = bindingImpl.getScoping();
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();
}
if (scopeAnnotation == null
&& (scoping == Scoping.EAGER_SINGLETON
|| scoping == Scoping.SINGLETON_ANNOTATION || scoping == Scoping.SINGLETON_INSTANCE)) {
scopeAnnotation = Singleton.class;
}
}
}
}
return scopeAnnotation;
}
示例12: RequestScopePropagator
import com.google.inject.Scope; //導入依賴的package包/類
protected RequestScopePropagator(
Scope scope,
ThreadLocalRequestContext local,
Provider<RequestScopedReviewDbProvider> dbProviderProvider) {
this.scope = scope;
this.local = local;
this.dbProviderProvider = dbProviderProvider;
}
示例13: ThreadLocalRequestScopePropagator
import com.google.inject.Scope; //導入依賴的package包/類
protected ThreadLocalRequestScopePropagator(
Scope scope,
ThreadLocal<C> threadLocal,
ThreadLocalRequestContext local,
Provider<RequestScopedReviewDbProvider> dbProviderProvider) {
super(scope, local, dbProviderProvider);
this.threadLocal = threadLocal;
}
示例14: createScopeMap
import com.google.inject.Scope; //導入依賴的package包/類
@Override
public Map<Scope, ComponentScope> createScopeMap() {
Map<Scope, ComponentScope> m = super.createScopeMap();
m.put(ServletScopes.REQUEST, ComponentScope.PerRequest);
return m;
}
示例15: scopeInstance
import com.google.inject.Scope; //導入依賴的package包/類
private static String scopeInstance(Scope scope) {
if (scope == Scopes.SINGLETON) {
return Scopes.class.getCanonicalName() + ".SINGLETON";
} else {
return "new " + scope.getClass().getCanonicalName() + "()";
}
}