use of org.glassfish.hk2.api.DynamicConfigurationService in project jersey by jersey.
the class Main method main.
public static void main(String[] args) {
ServiceLocatorFactory factory = ServiceLocatorFactory.getInstance();
ServiceLocator locator = factory.create("myLocator");
DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
DynamicConfiguration dc = dcs.createDynamicConfiguration();
AbstractBinder binder = new AbstractBinder() {
@Override
protected void configure() {
bind(HelloServiceImpl.class).to(GreetingService.class);
}
};
locator.inject(binder);
binder.bind(dc);
dc.commit();
GreetingWrapper wrapper = new GreetingWrapper(locator);
System.out.println("result: " + wrapper.getInjectedGreeting());
}
use of org.glassfish.hk2.api.DynamicConfigurationService in project jersey by jersey.
the class MyServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ServiceLocatorFactory factory = ServiceLocatorFactory.getInstance();
ServiceLocator locator = factory.create("myLocator");
DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
DynamicConfiguration dc = dcs.createDynamicConfiguration();
AbstractBinder binder = new AbstractBinder() {
@Override
protected void configure() {
bind(HelloServiceImpl.class).to(GreetingService.class);
}
};
binder.bind(dc);
dc.commit();
GreetingWrapper wrapper = new GreetingWrapper(locator);
response.getWriter().write("Greeting: " + wrapper.getInjectedGreeting());
locator.shutdown();
}
use of org.glassfish.hk2.api.DynamicConfigurationService in project Payara by payara.
the class EjbInjectedWithServiceLocator method installHK2Service.
@Override
public void installHK2Service() {
DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
DynamicConfiguration config = dcs.createDynamicConfiguration();
config.addActiveDescriptor(BasicService.class);
config.commit();
}
use of org.glassfish.hk2.api.DynamicConfigurationService in project Payara by payara.
the class HK2IntegrationExtension method afterDeploymentValidation.
/**
* Called by CDI after it has been completely validated. Will add the JIT resolver to HK2
* with the BeanManager
*
* @param event This is just to mark the type of the event
* @param manager The manager that will be used to get references
*/
@SuppressWarnings("unused")
private void afterDeploymentValidation(@Observes AfterDeploymentValidation event) {
if (locator == null)
return;
DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
DynamicConfiguration config = dcs.createDynamicConfiguration();
config.addActiveDescriptor(CDISecondChanceResolver.class);
config.addActiveDescriptor(CDIContextBridge.class);
config.commit();
}
use of org.glassfish.hk2.api.DynamicConfigurationService in project Payara by payara.
the class ConfigListenerTest method registerAndCreateHttpListenerContainer.
private HttpListenerContainer registerAndCreateHttpListenerContainer(ServiceLocator locator) {
HttpListenerContainer retVal = locator.getService(HttpListenerContainer.class);
if (retVal != null)
return retVal;
DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
Assert.assertNotNull(dcs);
DynamicConfiguration config = dcs.createDynamicConfiguration();
config.addActiveDescriptor(HttpListenerContainer.class);
config.commit();
return locator.getService(HttpListenerContainer.class);
}
Aggregations