Search in sources :

Example 1 with GuiceIntoHK2Bridge

use of org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge in project dropwizard-guicey by xvik.

the class GuiceBridgeActivator method activate.

/**
 * Activate hk guice bridge.
 */
public void activate() {
    GuiceBridge.getGuiceBridge().initializeGuiceBridge(locator);
    final GuiceIntoHK2Bridge guiceBridge = locator.getService(GuiceIntoHK2Bridge.class);
    guiceBridge.bridgeGuiceInjector(injector);
}
Also used : GuiceIntoHK2Bridge(org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge)

Example 2 with GuiceIntoHK2Bridge

use of org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge in project mycore by MyCoRe-Org.

the class MCRJerseyDefaultConfiguration method setupGuiceBridge.

/**
 * Adds the binding between guice and hk2. This binding is one directional.
 * You can add guice services into hk2 (jersey) resources. You cannot add
 * a hk2 service into guice.
 * <p>
 * <a href="https://hk2.java.net/guice-bridge/">about the bridge</a>
 * </p>
 *
 * @param resourceConfig the jersey resource configuration
 */
protected void setupGuiceBridge(ResourceConfig resourceConfig) {
    LogManager.getLogger().info("Initialize hk2 - guice bridge...");
    resourceConfig.register(new AbstractContainerLifecycleListener() {

        @Override
        public void onStartup(Container container) {
            ServiceLocator serviceLocator = container.getApplicationHandler().getServiceLocator();
            Injector injector = MCRInjectorConfig.injector();
            GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
            GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
            guiceBridge.bridgeGuiceInjector(injector);
        }
    });
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Container(org.glassfish.jersey.server.spi.Container) GuiceIntoHK2Bridge(org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge) Injector(com.google.inject.Injector) AbstractContainerLifecycleListener(org.glassfish.jersey.server.spi.AbstractContainerLifecycleListener)

Example 3 with GuiceIntoHK2Bridge

use of org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge in project graylog2-server by Graylog2.

the class Graylog2ServiceLocatorGenerator method create.

@Override
public ServiceLocator create(String name, ServiceLocator parent) {
    final ServiceLocator serviceLocator = super.create(name, parent);
    final Injector injector = GuiceInjectorHolder.getInjector().createChildInjector(new HK2IntoGuiceBridge(serviceLocator));
    GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
    final GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
    guiceBridge.bridgeGuiceInjector(injector);
    return serviceLocator;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) GuiceIntoHK2Bridge(org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge) Injector(com.google.inject.Injector) HK2IntoGuiceBridge(org.jvnet.hk2.guice.bridge.api.HK2IntoGuiceBridge)

Aggregations

GuiceIntoHK2Bridge (org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge)3 Injector (com.google.inject.Injector)2 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)2 AbstractContainerLifecycleListener (org.glassfish.jersey.server.spi.AbstractContainerLifecycleListener)1 Container (org.glassfish.jersey.server.spi.Container)1 HK2IntoGuiceBridge (org.jvnet.hk2.guice.bridge.api.HK2IntoGuiceBridge)1