本文整理汇总了Java中com.google.inject.Binder类的典型用法代码示例。如果您正苦于以下问题:Java Binder类的具体用法?Java Binder怎么用?Java Binder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Binder类属于com.google.inject包,在下文中一共展示了Binder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beanBind
import com.google.inject.Binder; //导入依赖的package包/类
/**
* auto bind interface impl
*
* @param binder
*/
private void beanBind(Binder binder) {
List<Class> classes = ClassScanner.scanClassByAnnotation(Bean.class, true);
for (Class impl : classes) {
Class<?>[] interfaceClasses = impl.getInterfaces();
Bean bean = (Bean) impl.getAnnotation(Bean.class);
String name = bean.name();
for (Class interfaceClass : interfaceClasses) {
if (interfaceClass == Serializable.class) {
continue;
}
try {
if (StringUtils.isBlank(name)) {
binder.bind(interfaceClass).to(impl);
} else {
binder.bind(interfaceClass).annotatedWith(Names.named(name)).to(impl);
}
} catch (Throwable ex) {
System.err.println(String.format("can not bind [%s] to [%s]", interfaceClass, impl));
}
}
}
}
示例2: configurePanoptes
import com.google.inject.Binder; //导入依赖的package包/类
private void configurePanoptes(Binder binder) {
String endpoint = config.getString("panoptes.service.url");
String clientSecret = config.getString("panoptes.service.client.secret");
Duration timeout = config.getDuration("panoptes.service.timeout");
PanoptesWebServiceFactory factory = new PanoptesWebServiceFactory(endpoint, timeout);
RetrofitServiceFactory authFactory = new BasicJWTAuthServiceFactorySC(endpoint, timeout);
AuthService authService = new BasicJWTAuthService(authFactory,
new Authorization("APIKEY", clientSecret));
binder.bind(String.class)
.annotatedWith(Names.named("PANOPTES_ENDPOINT"))
.toInstance(endpoint);
binder.bind(AuthService.class)
.annotatedWith(Names.named("PANOPTES_AUTH"))
.toInstance(authService);
PanoptesService service = new PanoptesService(factory, authService);
binder.bind(Long.class)
.annotatedWith(Names.named("PANOPTES_TIMEOUT"))
.toInstance(timeout.toMillis());
binder.bind(PanoptesWebServiceFactory.class).toInstance(factory);
binder.bind(ImageArchiveService.class).toInstance(service);
}
示例3: setUp
import com.google.inject.Binder; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
final RMContext mockRMContext =
TestRMWebApp.mockRMContext(3, numberOfRacks, numberOfNodesPerRack,
8 * TestRMWebApp.GiB);
injector =
WebAppTests.createMockInjector(RMContext.class, mockRMContext,
new Module() {
@Override
public void configure(Binder binder) {
try {
binder.bind(ResourceManager.class).toInstance(
TestRMWebApp.mockRm(mockRMContext));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
});
}
示例4: DynamicAnnouncementBinder
import com.google.inject.Binder; //导入依赖的package包/类
protected DynamicAnnouncementBinder(Binder binder)
{
keyBinder = newSetBinder(binder,
SERVICE_PROPERTY_TYPE,
ForDynamicAnnouncements.class);
getterBinder = newMapBinder(binder,
SERVICE_PROPERTY_TYPE,
new TypeLiteral<Function<Object, String>>() {},
ForDynamicAnnouncements.class);
objectBinder = newMapBinder(binder,
SERVICE_PROPERTY_TYPE,
new TypeLiteral<Object>() {},
ForDynamicAnnouncements.class);
}
示例5: configure
import com.google.inject.Binder; //导入依赖的package包/类
@Override
public void configure(Binder binder)
{
binder.bind(ThriftCodecFactory.class).to(CompilerThriftCodecFactory.class).in(Scopes.SINGLETON);
binder.bind(ThriftCatalog.class).in(Scopes.SINGLETON);
binder.bind(ThriftCodecManager.class).in(Scopes.SINGLETON);
newSetBinder(binder, new TypeLiteral<ThriftCodec<?>>() {}, InternalThriftCodec.class).permitDuplicates();
binder.bind(ClassLoader.class)
.annotatedWith(ForCompiler.class)
.toInstance(parent);
}
示例6: configure
import com.google.inject.Binder; //导入依赖的package包/类
@Override
public void configure(Binder binder) {
try (InputStream is1 = ClassLoader
.getSystemResourceAsStream("test-config.xml")) {
WxXmlCpInMemoryConfigStorage config = fromXml(
WxXmlCpInMemoryConfigStorage.class, is1);
WxCpServiceImpl wxService = new WxCpServiceImpl();
wxService.setWxCpConfigStorage(config);
binder.bind(WxCpServiceImpl.class).toInstance(wxService);
binder.bind(WxCpConfigStorage.class).toInstance(config);
} catch (IOException e) {
e.printStackTrace();
}
}
示例7: create
import com.google.inject.Binder; //导入依赖的package包/类
/**
* Creates a new duplex binder.
*
* @param binder the enclosing (public) binder
* @return a new duplex binder
*/
@NonNull
static DuplexBinder create(@NonNull final Binder binder) {
if(binder instanceof DuplexBinder) {
return (DuplexBinder) binder;
}
return new DuplexBinderImpl(binder, binder.newPrivateBinder());
}
示例8: configure
import com.google.inject.Binder; //导入依赖的package包/类
@Override
public void configure(Binder binder)
{
httpClientBinder(binder).addGlobalFilterBinding()
.to(DynamicAnnouncementFilter.class)
.asEagerSingleton();
jsonCodecBinder(binder).bindJsonCodec(JsonAnnouncement.class);
// Initialize various multibinders
DynamicAnnouncementBinder.dynamicAnnouncementBinder(binder);
}
示例9: configure
import com.google.inject.Binder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void configure(Binder binder) {
try {
// try to instantiate platform specific implementation
// will fail currently on Mac, thus the binding does not happen there
Class<? extends ISolidityCompiler> solidityCompilerClass = (Class<? extends ISolidityCompiler>) Class
.forName("com.yakindu.solidity.compiler.builder.SolidityCompiler");
binder.bind(ISolidityCompiler.class).to(solidityCompilerClass);
} catch (ClassNotFoundException e) {
System.err.println("SolidityCompilerModule: " + e.getMessage());
}
binder.bind(IPreferenceStore.class)
.toInstance((IPreferenceStore) SolidityActivator.getInstance().getPreferenceStore());
}
示例10: configure
import com.google.inject.Binder; //导入依赖的package包/类
@Override
public void configure(Binder binder) {
binder.bind(ActionMapping.class).toInstance(new ActionMapping());
binder.bind(ActionHandler.class).toInstance(new ActionHandler());
binder.bind(ViewFactory.class).to(DefaultViewFactory.class).in(Singleton.class);
binder.bind(ViewResolver.class).to(DefaultViewResolver.class).in(Singleton.class);
configureCaptcha(binder);
}
示例11: ListProvider
import com.google.inject.Binder; //导入依赖的package包/类
public ListProvider(Binder binder, List<Class<? extends T>> clazzes)
{
this.binder = binder;
this.clazzes.addAll(clazzes);
for( Class<? extends T> clazz : clazzes )
{
binder.bind(clazz);
}
}
示例12: configureContentProposalLabelProvider
import com.google.inject.Binder; //导入依赖的package包/类
/**
* Binds a specific label provider for the content assist use case.
*/
@Override
public void configureContentProposalLabelProvider(com.google.inject.Binder binder) {
binder.bind(org.eclipse.jface.viewers.ILabelProvider.class)
.annotatedWith(org.eclipse.xtext.ui.editor.contentassist.ContentProposalLabelProvider.class)
.to(N4JSContentAssistLabelProvider.class);
}
示例13: SetBinder
import com.google.inject.Binder; //导入依赖的package包/类
protected SetBinder(Binder binder, @Nullable Key<T> key) {
if(key == null) {
key = Key.get(new ResolvableType<T>(){}.in(getClass()));
}
this.binder = binder.skipSources(SetBinder.class);
this.elementType = key.getTypeLiteral();
this.collectionType = new ResolvableType<Set<T>>(){}.with(new TypeArgument<T>(this.elementType){});
this.multibinder = Multibinder.newSetBinder(binder, key);
}
示例14: configure
import com.google.inject.Binder; //导入依赖的package包/类
@Override
public void configure(Binder binder) {
binder.bind(EthereumConnector.class).in(Scopes.SINGLETON);
binder.bind(EthereumMetadata.class).in(Scopes.SINGLETON);
binder.bind(EthereumWeb3jProvider.class).in(Scopes.SINGLETON);
binder.bind(EthereumSplitManager.class).in(Scopes.SINGLETON);
binder.bind(EthereumRecordSetProvider.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfig(EthereumConnectorConfig.class);
jsonBinder(binder).addDeserializerBinding(Type.class).to(TypeDeserializer.class);
}
示例15: configureConceptService
import com.google.inject.Binder; //导入依赖的package包/类
private void configureConceptService(Binder binder) {
String endpoint = config.getString("concept.service.url");
Duration timeout = config.getDuration("concept.service.timeout");
KBWebServiceFactory factory = new KBWebServiceFactory(endpoint, timeout, defaultExecutor);
KBConceptService service = new KBConceptService(factory);
// --- Using a local cache
CachedConceptService cachedService = new CachedConceptService(service);
List<String> cachedConceptTemplates = config.getStringList("app.annotation.details.cache");
cachedService.prefetch(cachedConceptTemplates);
binder.bind(String.class)
.annotatedWith(Names.named("CONCEPT_ENDPOINT"))
.toInstance(endpoint);
binder.bind(KBWebServiceFactory.class).toInstance(factory);
binder.bind(ConceptService.class).toInstance(cachedService);
}