use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class InjectionManagerFactory method createInjectionManager.
/**
* Create new initialized server injection manager.
*
* @param applicationProperties map of application-specific properties.
* @return new initialized server injection manager.
*/
public static InjectionManager createInjectionManager(Map<String, Object> applicationProperties) {
InjectionManager injectionManager = Injections.createInjectionManager();
injectionManager.register(new ServerBinder(applicationProperties, injectionManager));
return injectionManager;
}
use of org.glassfish.jersey.internal.inject.InjectionManager 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.InjectionManager in project jersey by jersey.
the class CustomInjectablesApplicationTest method plainHK2Test.
@Test
public void plainHK2Test() throws Exception {
final InjectionManager locator = Injections.createInjectionManager(new RequestScope.Binder(), new AbstractBinder() {
@Override
protected void configure() {
bindAsContract(MyInjectablePerRequest.class).in(RequestScoped.class);
bindAsContract(MyInjectableSingleton.class).in(Singleton.class);
}
});
final RequestScope requestScope = locator.getInstance(RequestScope.class);
final MyInjectableSingleton myInjectableSingleton = locator.getInstance(MyInjectableSingleton.class);
assertEquals(myInjectableSingleton, locator.getInstance(MyInjectableSingleton.class));
final MyInjectablePerRequest myInjectablePerRequest = requestScope.runInScope(new Callable<MyInjectablePerRequest>() {
@Override
public MyInjectablePerRequest call() throws Exception {
final MyInjectablePerRequest myInjectablePerRequest = locator.getInstance(MyInjectablePerRequest.class);
assertEquals(myInjectablePerRequest, locator.getInstance(MyInjectablePerRequest.class));
return myInjectablePerRequest;
}
});
requestScope.runInScope(new Runnable() {
@Override
public void run() {
assertNotSame(myInjectablePerRequest, locator.getInstance(MyInjectablePerRequest.class));
}
});
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class CommonConfigTest method testConfigureFeatureInstancesProviderInstances.
@Test
public void testConfigureFeatureInstancesProviderInstances() throws Exception {
final InstanceFeatureA f1 = new InstanceFeatureA();
config.register(f1);
final InstanceFeatureA f2 = new InstanceFeatureA(true);
config.register(f2);
InjectionManager injectionManager = Injections.createInjectionManager();
config.configureMetaProviders(injectionManager);
assertTrue(config.getConfiguration().isEnabled(f1));
assertFalse(config.getConfiguration().isEnabled(f2));
final Set<Object> providerInstances = config.getInstances();
assertEquals(2, providerInstances.size());
final Set<Object> pureProviderInstances = config.getComponentBag().getInstances(ComponentBag.excludeMetaProviders(injectionManager));
assertEquals(1, pureProviderInstances.size());
int a = 0;
int b = 0;
for (final Object instance : pureProviderInstances) {
if (instance instanceof CustomReaderA) {
a++;
} else {
b++;
}
}
assertEquals(1, a);
assertEquals(0, b);
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class CommonConfigTest method testFeatureInjectionsBindInFeature.
@Test
@Ignore
public void testFeatureInjectionsBindInFeature() throws Exception {
config.register(new BindInjectMeInFeature());
config.register(InjectIntoFeatureClass.class);
config.register(new InjectIntoFeatureInstance());
final InjectionManager injectionManager = Injections.createInjectionManager();
config.configureMetaProviders(injectionManager);
assertThat("Feature instance not injected", config.getProperty("instance-injected").toString(), is("true"));
assertThat("Feature class not injected", config.getProperty("class-injected").toString(), is("true"));
}
Aggregations