本文整理匯總了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);
}