Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the Jersey injection manager #253

Closed
wants to merge 1 commit into from
Closed

Conversation

dmetzler
Copy link

@dmetzler dmetzler commented Apr 18, 2019

Expose the Jersey injection manager to be able to use it outside of Jersey resources

Description of changes:

This PR just add a method on the JerseyLambdaContainerHandler that exposes the Jersey injections manager. It's very useful as it allows to use it to build the whole dependency tree.

// List of application bindings to configure injections, this
// allows to have different injection in tests
protected abstract List<Binder> binders();

public AbstractServiceHandler() {
  ResourceConfig jerseyApplication = new ResourceConfig()
                                             .packages("com.acme.jaxrs.resources");

  binders().forEach(jerseyApplication::register);

  handler = JerseyLambdaContainerHandler.getAwsProxyHandler(jerseyApplication);
  im = handler.getInjectionManager();
  ServiceFactory.setInstance(im.getInstance(Service.class));
}

If the lambda code also handles other type of event, the same injector can then be reused:

public String handleS3Request(S3Event s3Event) {
  Service service = im.getInstance(Service.class);
  return service.handleEvent(adapt(s3Event));
}

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Collaborator

@sapessi sapessi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I'll merge with the next minor release

@sapessi sapessi added this to the Release 1.3.1 milestone Jun 20, 2019
@sapessi
Copy link
Collaborator

sapessi commented Jun 20, 2019

Merged manually in the core branch where I'm working on the new changes. Closing this PR.

@sapessi sapessi closed this Jun 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants