use of org.glassfish.jersey.internal.inject.Binder in project jersey by jersey.
the class CdiComponentProvider method bindHk2ClassAnalyzer.
private void bindHk2ClassAnalyzer() {
ClassAnalyzer defaultClassAnalyzer = injectionManager.getInstance(ClassAnalyzer.class, ClassAnalyzer.DEFAULT_IMPLEMENTATION_NAME);
int skippedElements = methodsToSkip.size() + fieldsToSkip.size();
ClassAnalyzer customizedClassAnalyzer = skippedElements > 0 ? new InjecteeSkippingAnalyzer(defaultClassAnalyzer, methodsToSkip, fieldsToSkip) : defaultClassAnalyzer;
Binder binder = new AbstractBinder() {
@Override
protected void configure() {
bind(customizedClassAnalyzer).analyzeWith(ClassAnalyzer.DEFAULT_IMPLEMENTATION_NAME).to(ClassAnalyzer.class).named(CDI_CLASS_ANALYZER);
}
};
injectionManager.register(binder);
}
use of org.glassfish.jersey.internal.inject.Binder in project jersey by jersey.
the class SaxParserFactoryInjectionProviderTest method createInjectionManager.
public static InjectionManager createInjectionManager(Binder... customBinders) {
Binder[] binders = new Binder[customBinders.length + 2];
binders[0] = new AbstractBinder() {
@Override
protected void configure() {
bindFactory(() -> EMPTY_CONFIG).to(Configuration.class);
bindFactory(SaxParserFactoryInjectionProvider.class, Singleton.class).to(SAXParserFactory.class).in(PerThread.class);
bindAsContract(MySPFProvider.class).in(Singleton.class);
}
};
System.arraycopy(customBinders, 0, binders, 2, customBinders.length);
return Injections.createInjectionManager(binders);
}
use of org.glassfish.jersey.internal.inject.Binder in project jersey by jersey.
the class CustomInjectablesApplicationTest method plainHK2DynamicTest.
@Test
public void plainHK2DynamicTest() throws Exception {
InjectionManager injectionManager = Injections.createInjectionManager(new RequestScope.Binder());
Binder binder = new AbstractBinder() {
@Override
protected void configure() {
bindAsContract(MyInjectablePerRequest.class).in(RequestScoped.class);
bindAsContract(MyInjectableSingleton.class).in(Singleton.class);
}
};
injectionManager.register(binder);
final RequestScope requestScope = injectionManager.getInstance(RequestScope.class);
final MyInjectableSingleton myInjectableSingleton = injectionManager.getInstance(MyInjectableSingleton.class);
assertEquals(myInjectableSingleton, injectionManager.getInstance(MyInjectableSingleton.class));
final MyInjectablePerRequest myInjectablePerRequest = requestScope.runInScope(new Callable<MyInjectablePerRequest>() {
@Override
public MyInjectablePerRequest call() throws Exception {
final MyInjectablePerRequest myInjectablePerRequest = injectionManager.getInstance(MyInjectablePerRequest.class);
assertEquals(myInjectablePerRequest, injectionManager.getInstance(MyInjectablePerRequest.class));
return myInjectablePerRequest;
}
});
requestScope.runInScope(new Runnable() {
@Override
public void run() {
assertNotSame(myInjectablePerRequest, injectionManager.getInstance(MyInjectablePerRequest.class));
}
});
}
use of org.glassfish.jersey.internal.inject.Binder in project jersey by jersey.
the class SpringComponentProvider method initialize.
@Override
public void initialize(InjectionManager injectionManager) {
this.injectionManager = injectionManager;
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine(LocalizationMessages.CTX_LOOKUP_STARTED());
}
ServletContext sc = injectionManager.getInstance(ServletContext.class);
if (sc != null) {
// servlet container
ctx = WebApplicationContextUtils.getWebApplicationContext(sc);
} else {
// non-servlet container
ctx = createSpringContext();
}
if (ctx == null) {
LOGGER.severe(LocalizationMessages.CTX_LOOKUP_FAILED());
return;
}
LOGGER.config(LocalizationMessages.CTX_LOOKUP_SUCESSFUL());
// initialize HK2 spring-bridge
HK2InjectionManager hk2InjectionManager = (HK2InjectionManager) injectionManager;
SpringBridge.getSpringBridge().initializeSpringBridge(hk2InjectionManager.getServiceLocator());
SpringIntoHK2Bridge springBridge = injectionManager.getInstance(SpringIntoHK2Bridge.class);
springBridge.bridgeSpringBeanFactory(ctx);
// register Spring @Autowired annotation handler with HK2 ServiceLocator
Binder binder = new AbstractBinder() {
@Override
protected void configure() {
bind(new AutowiredInjectResolver(ctx)).to(InjectionResolver.class);
bind(ctx).to(ApplicationContext.class).named("SpringContext");
}
};
injectionManager.register(binder);
LOGGER.config(LocalizationMessages.SPRING_COMPONENT_PROVIDER_INITIALIZED());
}
Aggregations