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

HK2 DI example for LyoD #31

Closed
wants to merge 4 commits into from
Closed

HK2 DI example for LyoD #31

wants to merge 4 commits into from

Conversation

berezovskyi
Copy link
Member

@berezovskyi berezovskyi commented Apr 27, 2019

This is the DI example for inclusion in LyoD.

The JAX-RS service side is framework-independent and relies on JSR-330 annotations.

Unfortunately, the injection framework configuration was really tricky:

  • The community is moving towards CDI (see Microprofile)
  • Jersey has long used HK2, Sun's DI used for Glassfish and other things.
  • Jersey has added support for CDI 1 some time ago.
  • CDI 2 is the latest release, but support for it in Jersey is experimental.
  • Weld is the reference implementation of both CDI 1.2 and CDI 2.0.
  • Weld is supported in Jetty 9.4 "out of the box" but only the Weld 3, which is the implementation of CDI 2.0
  • Jetty support out of the box only works for standalone servers not the ones we start from maven via jetty:run (I did not want to use hacks with forked Jetty instances).
  • Experimental Jersey support for CDI 2 is only shown (explained with examples) for Java SE where you run Jetty in an embedded mode (ie. have a main() method and start Jetty programmatically). I did not want to do this because it would tie us to Jetty.
  • Wildfly should have support for CDI out of the box but that would require giving up on lightweight Jetty and I did not manage to set it up from the first try.

I am pretty sure there is a flaw in my thinking at some step above. If you can help me get CDI 1.2 (or better yet, CDI 2.0) working, it would be fantastic!

Still, if you wish to use something else that Jersey and HK2 injector, you only need to change the binding config code in the Application class.

@berezovskyi berezovskyi force-pushed the b-lyo4-hk2 branch 4 times, most recently from 6ebe844 to b289d41 Compare April 27, 2019 13:41
Inject the Manager singleton instance

Signed-off-by: Andrew Berezovskyi <andriib@kth.se>
@berezovskyi
Copy link
Member Author

Jad asked me to prepare a manual DI example with interfaces, singletons and factories and I will do it soon.

Signed-off-by: Andrew Berezovskyi <andriib@kth.se>
@berezovskyi
Copy link
Member Author

@neormx, you have experience with WildFly?

@jadelkhoury jadelkhoury deleted the b-lyo4-hk2 branch September 24, 2019 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant