Replacing com.google.inject with javax.inject

JavaGwtDependency InjectionGuiceGwt Gin

Java Problem Overview


Is it true that javax.inject annotations can function as direct replacements for com.google.inject?

So that, if I replaced all my current guice/gin annotations with those from javax.inject, my app would compile and run just fine?

First, does javax.inject cover all the bases that google.inject cover?

Java Solutions


Solution 1 - Java

Yes, it will work fine. In fact the author of guice (Bob Lee) is a spec-lead for the javax.inject specification.

javax.inject.Inject does not have the optional attribute, so if you want an optional dependency, you'd have to use the guice annotation.

Solution 2 - Java

Actually, I have chosen to refrain from switching to javax.inject, because I find the spec much minimalistic in comparison to what Guice provides (which I use):

  • @Optional as mentioned by @Bozho
  • @ImplementedBy which is very useful when you want to reduce the number of explicit bindings (for code clarity) and when you want to be able to easily override the default @ImplementedBy binding if you need (e.g. for integration tests).

There are probably others but for me these 2 are showstoppers already.

Solution 3 - Java

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBlessed GeekView Question on Stackoverflow
Solution 1 - JavaBozhoView Answer on Stackoverflow
Solution 2 - JavajfpoilpretView Answer on Stackoverflow
Solution 3 - Javauser849827View Answer on Stackoverflow