本文整理汇总了Java中com.google.inject.binder.ScopedBindingBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ScopedBindingBuilder类的具体用法?Java ScopedBindingBuilder怎么用?Java ScopedBindingBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScopedBindingBuilder类属于com.google.inject.binder包,在下文中一共展示了ScopedBindingBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: bindingModule
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
public Module bindingModule() {
return new KeyedManifest.Impl(method) {
@Override
public void configure() {
final Binder binder = binder().withSource(method);
if(!hasReturnValue()) {
binder.addError("Cannot bind this method as a provider because it does not return a value");
return;
}
install(InjectableMethod.this);
final ScopedBindingBuilder builder = binder.bind(providedKey).toProvider(asProvider());
if(scope != null) builder.in(scope);
}
};
}
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:18,代码来源:InjectableMethod.java
示例2: toProvider
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
@Override
public ScopedBindingBuilder toProvider(Provider<? extends T> provider) {
return new ScopedBindingBuilderImpl(
delegate.toProvider(new Supplier<T>() {
@Override
public T get() {
return provider.get();
}
@Inject
public void init(Injector injector) {
injector.injectMembers(provider);
}
}));
}
开发者ID:ruediste,项目名称:salta,代码行数:17,代码来源:LinkedBindingBuilderImpl.java
示例3: bindFutureProvider
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
void bindFutureProvider(PrivateBinder binder) {
binder = binder.withSource(source);
ScopedBindingBuilder scoper = binder.bind(bindingKey).toProvider(this);
if (isVoid(method)) {
scoper.asEagerSingleton();
} else {
if (scopeAnnotation != null) {
scoper.in(scopeAnnotation);
}
if (exposedBinding) {
binder.expose(bindingKey);
}
}
}
开发者ID:immutables,项目名称:miscellaneous,代码行数:17,代码来源:Providers.java
示例4: applyScoping
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的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;
}
});
}
开发者ID:zorzella,项目名称:guiceberry,代码行数:26,代码来源:ModuleWriter.java
示例5: configure
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
void configure(Binder binder) {
binder = binder.withSource(method);
SecondaryBinder<?, ?> sbinder =
ThrowingProviderBinder.create(binder).bind(checkedProvider, key.getTypeLiteral());
if (key.getAnnotation() != null) {
sbinder = sbinder.annotatedWith(key.getAnnotation());
} else if (key.getAnnotationType() != null) {
sbinder = sbinder.annotatedWith(key.getAnnotationType());
}
sbinder.scopeExceptions(scopeExceptions);
ScopedBindingBuilder sbbuilder = sbinder.toProviderMethod(this);
if (scopeAnnotation != null) {
sbbuilder.in(scopeAnnotation);
}
if (exposed) {
// the cast is safe 'cause the only binder we have implements PrivateBinder. If there's a
// misplaced @Exposed, calling this will add an error to the binder's error queue
((PrivateBinder) binder).expose(sbinder.getKey());
}
CheckedProvideUtils.validateExceptions(
binder, exceptionTypes, sbinder.getExceptionTypes(), checkedProvider);
}
开发者ID:google,项目名称:guice,代码行数:26,代码来源:CheckedProviderMethod.java
示例6: configure
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
void configure(Binder binder) {
binder = binder.withSource(method);
SecondaryBinder<?, ?> sbinder =
ThrowingProviderBinder.create(binder)
.bind(checkedProvider, key.getTypeLiteral());
if(key.getAnnotation() != null) {
sbinder = sbinder.annotatedWith(key.getAnnotation());
} else if(key.getAnnotationType() != null) {
sbinder = sbinder.annotatedWith(key.getAnnotationType());
}
ScopedBindingBuilder sbbuilder = sbinder.toProviderMethod(this);
if(scopeAnnotation != null) {
sbbuilder.in(scopeAnnotation);
}
if (exposed) {
// the cast is safe 'cause the only binder we have implements PrivateBinder. If there's a
// misplaced @Exposed, calling this will add an error to the binder's error queue
((PrivateBinder) binder).expose(sbinder.getKey());
}
CheckedProvideUtils.validateExceptions(
binder, exceptionTypes, sbinder.getExceptionTypes(), checkedProvider);
}
开发者ID:cgruber,项目名称:guice-old,代码行数:26,代码来源:CheckedProviderMethod.java
示例7: forAnnotation
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
public static Scoping forAnnotation(final Class<? extends Annotation> scopingAnnotation) {
if (scopingAnnotation == Singleton.class
|| scopingAnnotation == javax.inject.Singleton.class) {
return SINGLETON_ANNOTATION;
}
return new Scoping() {
@Override public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
return visitor.visitScopeAnnotation(scopingAnnotation);
}
@Override public Class<? extends Annotation> getScopeAnnotation() {
return scopingAnnotation;
}
@Override public String toString() {
return scopingAnnotation.getName();
}
@Override public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
scopedBindingBuilder.in(scopingAnnotation);
}
};
}
开发者ID:cgruber,项目名称:guice-old,代码行数:25,代码来源:Scoping.java
示例8: forInstance
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的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);
}
};
}
开发者ID:cgruber,项目名称:guice-old,代码行数:24,代码来源:Scoping.java
示例9: configure
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
@Override public void configure(final Env env, final Config conf, final Binder binder)
throws Exception {
boolean dev = env.name().equals("dev");
ScopedBindingBuilder provider = binder.bind(M)
.toProvider(APIProvider.class);
if (!dev) {
provider.asEagerSingleton();
}
Path dir = Optional.ofNullable(basedir).orElse(Paths.get(conf.getString("user.dir")));
ApiParser parser = new ApiParser(dir, filter);
customizer.forEach(parser::modify);
binder.bind(ApiParser.class).toInstance(parser);
String contextPath = conf.getString("application.path");
if (swaggerOptions != null) {
swagger(contextPath, env.router(), swaggerOptions, swagger);
}
if (ramlOptions != null) {
raml(contextPath, env.router(), ramlOptions, raml);
}
}
开发者ID:jooby-project,项目名称:jooby,代码行数:24,代码来源:ApiTool.java
示例10: forAnnotation
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
public static Scoping forAnnotation(final Class<? extends Annotation> scopingAnnotation) {
if (scopingAnnotation == Singleton.class
|| scopingAnnotation == javax.inject.Singleton.class) {
return SINGLETON_ANNOTATION;
}
return new Scoping() {
public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
return visitor.visitScopeAnnotation(scopingAnnotation);
}
@Override public Class<? extends Annotation> getScopeAnnotation() {
return scopingAnnotation;
}
@Override public String toString() {
return scopingAnnotation.getName();
}
public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
scopedBindingBuilder.in(scopingAnnotation);
}
};
}
开发者ID:utopiazh,项目名称:google-guice,代码行数:25,代码来源:Scoping.java
示例11: forInstance
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的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);
}
};
}
开发者ID:utopiazh,项目名称:google-guice,代码行数:24,代码来源:Scoping.java
示例12: bindProvidersInScope
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
private void bindProvidersInScope(PrivateBinder privateBinder) {
ScopedBindingBuilder scoper = privateBinder.bind(providersClass);
if (scopeAnnotation != null) {
scoper.in(scopeAnnotation);
}
for (EventualProvider<?> p : providers) {
p.bindFutureProvider(privateBinder);
}
}
开发者ID:immutables,项目名称:miscellaneous,代码行数:12,代码来源:Providers.java
示例13: visit
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
@Override
public <T> Void visit(Binding<T> binding) {
final Key<T> key = binding.getKey();
if (!keysToIntercept.contains(key)) {
return super.visit(binding);
}
binding.acceptTargetVisitor(new DefaultBindingTargetVisitor<T, Void>() {
@Override
public Void visit(UntargettedBinding<? extends T> untargettedBinding) {
binder.addError("Cannot intercept bare binding of %s. " +
"You may only intercept bindings that bind a class to something.", key);
return null;
}
});
Key<T> anonymousKey = Key.get(key.getTypeLiteral(), UniqueAnnotations.create());
binder.bind(key).toProvider(new InterceptingProvider<T>(key, binder.getProvider(anonymousKey)));
ScopedBindingBuilder scopedBindingBuilder = bindKeyToTarget(binding, binder, anonymousKey);
// we scope the user's provider, not the interceptor. This is dangerous,
// but convenient. It means that although the user's provider will live
// in its proper scope, the intereptor gets invoked without a scope
applyScoping(binding, scopedBindingBuilder);
keysIntercepted.add(key);
return null;
}
开发者ID:zorzella,项目名称:guiceberry,代码行数:31,代码来源:InterceptingBindingsBuilder.java
示例14: visit
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
@Override
public <T> Void visit(Binding<T> binding) {
final Key<T> key = binding.getKey();
if (!keysToIntercept.contains(key)) {
return super.visit(binding);
}
binding.acceptTargetVisitor(new DefaultBindingTargetVisitor<T, Void>() {
@Override
public Void visit(UntargettedBinding<? extends T> untargettedBinding) {
binder.addError("Cannot intercept bare binding of %s. " +
"You may only intercept bindings that bind a class to something.", key);
return null;
}
});
Key<T> anonymousKey = Key.get(key.getTypeLiteral(), UniqueAnnotations.create());
binder.bind(key).toProvider(new InterceptingProvider<T>(key, binder.getProvider(anonymousKey)));
ScopedBindingBuilder scopedBindingBuilder = bindKeyToTarget(binding, binder, anonymousKey);
// we scope the user's provider, not the interceptor. This is dangerous,
// but convenient. It means that although the user's provider will live
// in its proper scope, the interceptor gets invoked without a scope
applyScoping(binding, scopedBindingBuilder);
keysIntercepted.add(key);
return null;
}
开发者ID:zorzella,项目名称:guiceberry,代码行数:31,代码来源:InterceptingBindingsBuilder.java
示例15: bindModelClass
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
/**
* Bind also the concrete model class, this binding is necesary to add the scope also to the concrete class.
* @param description
*/
private void bindModelClass(StatisticDescriptor description) {
Class<?> statisticModelClass = description.getModelClass();
ScopedBindingBuilder binderBuilder = bind(statisticModelClass);
applyScope(description, binderBuilder);
}
开发者ID:lafourchette,项目名称:solrmeter,代码行数:11,代码来源:StatisticsModule.java
示例16: toProviderMethod
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
ScopedBindingBuilder toProviderMethod(CheckedProviderMethod<?> target) {
Key<CheckedProviderMethod<?>> targetKey =
Key.get(CHECKED_PROVIDER_METHOD_TYPE, UniqueAnnotations.create());
binder.bind(targetKey).toInstance(target);
return toInternal(targetKey);
}
开发者ID:google,项目名称:guice,代码行数:8,代码来源:ThrowingProviderBinder.java
示例17: forAnnotation
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
public static Scoping forAnnotation(final Class<? extends Annotation> scopingAnnotation) {
if (scopingAnnotation == Singleton.class || scopingAnnotation == javax.inject.Singleton.class) {
return SINGLETON_ANNOTATION;
}
return new Scoping() {
@Override
public <V> V acceptVisitor(BindingScopingVisitor<V> visitor) {
return visitor.visitScopeAnnotation(scopingAnnotation);
}
@Override
public Class<? extends Annotation> getScopeAnnotation() {
return scopingAnnotation;
}
@Override
public String toString() {
return scopingAnnotation.getName();
}
@Override
public void applyTo(ScopedBindingBuilder scopedBindingBuilder) {
scopedBindingBuilder.in(scopingAnnotation);
}
};
}
开发者ID:google,项目名称:guice,代码行数:28,代码来源:Scoping.java
示例18: forInstance
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
public static Scoping forInstance(final Scope scope) {
if (scope == Scopes.SINGLETON) {
return SINGLETON_INSTANCE;
} else if (scope == Scopes.NO_SCOPE) {
return EXPLICITLY_UNSCOPED;
}
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);
}
};
}
开发者ID:google,项目名称:guice,代码行数:30,代码来源:Scoping.java
示例19: toProviderMethod
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
ScopedBindingBuilder toProviderMethod(CheckedProviderMethod<?> target) {
Key<CheckedProviderMethod> targetKey =
Key.get(CheckedProviderMethod.class, UniqueAnnotations.create());
binder.bind(targetKey).toInstance(target);
return toInternal(targetKey);
}
开发者ID:cgruber,项目名称:guice-old,代码行数:8,代码来源:ThrowingProviderBinder.java
示例20: toProvider
import com.google.inject.binder.ScopedBindingBuilder; //导入依赖的package包/类
public ScopedBindingBuilder toProvider(
Key<? extends javax.inject.Provider<? extends T>> providerKey) {
delegate.toProvider(providerKey);
annotation.targetType = TargetType.PROVIDER_KEY;
annotation.target = providerKey;
return this;
}
开发者ID:cgruber,项目名称:guice-old,代码行数:8,代码来源:RealElement.java
注:本文中的com.google.inject.binder.ScopedBindingBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论