Skip to content

Multiple ServiceLocators #46

@jmif

Description

@jmif

I've just upgraded to dropwizard-guicier and have a question regarding the logic used in the ServiceLocatorGenerator installed here.

In previous versions of this repo and in dropwizard-guice the Guice Injector is is used to generate the ServiceLocator regardless of the __HK2_ index (it uses Guice as the source injector for 0 / 1 / 2 / etc). In 1.3.5.0 (and I believe a few of the previous versions as well) only one HK2 service locator is overridden.

My Jersey clients use some @Providers that need to be injected from the Guice injector and this injection worked because every HK2 ServiceLocator was sent to the Guice injector in dropwizard-guice. Now it seems only the Jersey server one is proxied and thus my Jersey Clients are broken. The other HK2 generated items get a new service locator.

Is this intentional / expected? If so is there a recommended work around? I'm new to this area of Jersey and am just beginning to understand the way HK2 works / the Jersey Guice binding works, so I can't tell what the expected / desirable behavior is.

For context, this is how I create the Jersey Client inside of Guice.

@Provides
public synchronized Client getJerseyClient(Environment environment, ApiApplication application,
                                               ApiConfiguration configuration) {

    if (this.jerseyHttpClient == null) {
        this.jerseyHttpClient = new JerseyClientBuilder(environment)
                .using(configuration.getJerseyClientConfiguration())
                .build(application.getName() + "-jersey-client")
                .register(MessageBodyReaderThatRequiresInjection.class);
    }

    return this.jerseyHttpClient;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions