-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add JEE (jakarta.inject) support to Guice #1630
Conversation
Support for - jakarta.inject.Inject - jakarta.inject.Named - jakarta.inject.Qualifier - jakarta.inject.Scope - jakarta.inject.Singleton These injections are functional equivalent to the javax.inject counterparts.
56de719
to
540e6c7
Compare
Adds support for jakarta providers. These can be used interchangeably with their native and javax.inject counterparts.
This is a straight port from the guice-servlet code to support the new jakarta servlet API classes (jakarta.*).
Could at least someone approve the workflow execution so that we can see whether this would apply to the current code base or not? |
I would also be interested in seeing this done as we want to move a big application frm JavaEE to JakartaEE to go along with new developments. |
please add this support! |
Mmmm, I've migrated everything to Jakarta namespace already (guicedee.com), and did the persistence and servlet addons as well, you can just use the jars as a replacement, I get this allows for both javax and jakarta, but personally I don't think that's ever going to fly hey, also the extensions assistedinject, persistence, servlet, etc aren't updated so this PR would break that entire ecosystem :) I think this is only required if you are using Guice in a very funny manner |
Hey Marc. Thank you for your effort with guicedee. My requirements are different, I have large applications that will migrate slowly. A "just everything from A to B" migration is impossible and not feasible. The challenge with sticking with JSR 330 is that most of the JEE ecosystem is moving to Jakarta DI 2.0 (I think JSR 330 is the "old" javax.inject" and Jakarta EE DI 2.0 is the "new" jakarta.inject spec). Making it possible to mix those is crucial for large scale migrations. I am using this change in a number or projects; I understand that you want to lobby for "your work", however this is a different use case. As for the other modules; modifying those is a lesser concern at least to me; it should not be hard to do so. This PR is intended as a starting point for a discussion. |
This looks really good, and feels like the right direction for Guice. Is there anyone left at Google still working on this? |
It seems that within Google, Guice is one of these "works for us and is stable" projects. |
@hgschmie i suppose, it could also be viewed as ee got thrown in the trash and superseded with native modules (and then ee got picked up out of the trash for $$$), so why bother, or the entire ecosystem of google uses this so any change must be extremely careful and how many of their applications must switch to jakarta in order to make it viable, either way, it's not your only option, there are guice shaded libraries out there that have already done the move, and enabled modularization and native modules with it as well, you know, that continuous improvement cycle.... I don't think it's fair to say the project isn't moving when clearly it still is, just because it's not entertaining (yet) the idea of managing an ecosystem that was cancelled for a much better solution with Java 9, |
/cc @sameb |
@hgschmie - can you either revise this PR or send a new one that drops support for jakarta.inject.Provider, and drops the new servlet extension? That is, it only recognizes the new jakarta.inject.{Inject,Scope,Qualifier, Named,Singleton} annotations? Supporting the Provider interface is much trickier and requires a lot more thought as to how to do that correctly. (And supporting a forked servlet extension is its own discussion.) Thanks. |
Guice's greatest virtue is its agility and that it is a DI library by itself with no frills added. Other DI and CDI solutions are fullstack If you want to use more modern application servers ( or other solutiones....) , on many occasions are forced to do a full stack migration. In itself a migration to , for example, toSpring, Micronaut, Quarkus is a full stack migration generating complicated dependencies that can condition the evolution of the applications..... Indirectly, not supporting this small functionality is forcing developers to do full stack migrations and it's not easy to get out of there! Reconsider! |
Please support Jakarta namespace. This library can be considered as a dead technology if not supporting Jakarta properly. |
I need to use Jakarta too. I have a project based on RestEasy and the Guice support was dropped after version 4.7.4.Final (pretty old) because Guice is missing Jakarta support! |
…rt for `toProvider(...)` to instances of `jakarta.inject.Provider` or classes/keys/typeLiterals of type `jakarta.inject.Provider`. See #1383 (comment) for details of the plans. The Guice 6.0 release will support `javax.inject` _and_ `jakarta.inject` (excluding `toProvider()` support for `jakarta.inject`), and the Guice 7.0+ release will remove the `javax.inject` references. Further background on these issues: * #1630 * #1679 * #1490 * #1383 PiperOrigin-RevId: 526763665
This does not add support for `toProvider(...)` to instances of `jakarta.inject.Provider` or classes/keys/typeLiterals of type `jakarta.inject.Provider`. See #1383 (comment) for details of the plans. The Guice 6.0 release will support `javax.inject` _and_ `jakarta.inject` (excluding `toProvider()` support for `jakarta.inject`), and the Guice 7.0+ release will remove the `javax.inject` references. Further background on these issues: * #1630 * #1679 * #1490 * #1383 PiperOrigin-RevId: 526763665
This does not add support for `toProvider(...)` to instances of `jakarta.inject.Provider` or classes/keys/typeLiterals of type `jakarta.inject.Provider`. See #1383 (comment) for details of the plans. The Guice 6.0 release will support `javax.inject` _and_ `jakarta.inject` (excluding `toProvider()` support for `jakarta.inject`), and the Guice 7.0+ release will remove the `javax.inject` references. Further background on these issues: * #1630 * #1679 * #1490 * #1383 PiperOrigin-RevId: 526763665
This does not add support for `toProvider(...)` to instances of `jakarta.inject.Provider` or classes/keys/typeLiterals of type `jakarta.inject.Provider`. See #1383 (comment) for details of the plans. The Guice 6.0 release will support `javax.inject` _and_ `jakarta.inject` (excluding `toProvider()` support for `jakarta.inject`), and the Guice 7.0+ release will remove the `javax.inject` references. Further background on these issues: * #1630 * #1679 * #1490 * #1383 PiperOrigin-RevId: 526763665
This does not add support for `toProvider(...)` to instances of `jakarta.inject.Provider` or classes/keys/typeLiterals of type `jakarta.inject.Provider`. See #1383 (comment) for details of the plans. The Guice 6.0 release will support `javax.inject` _and_ `jakarta.inject` (excluding `toProvider()` support for `jakarta.inject`), and the Guice 7.0+ release will remove the `javax.inject` references. Further background on these issues: * #1630 * #1679 * #1490 * #1383 PiperOrigin-RevId: 526763665
This does not add support for `toProvider(...)` to instances of `jakarta.inject.Provider` or classes/keys/typeLiterals of type `jakarta.inject.Provider`. See #1383 (comment) for details of the plans. The Guice 6.0 release will support `javax.inject` _and_ `jakarta.inject` (excluding `toProvider()` support for `jakarta.inject`), and the Guice 7.0+ release will remove the `javax.inject` references. Further background on these issues: * #1630 * #1679 * #1490 * #1383 PiperOrigin-RevId: 527349023
Hi Folks. As of 5eff2ea, Guice Core mostly supports
As such, I'm going to close this PR. Thank you for your help in making this happen! If anyone has further comments, please continue the discussion on #1383 (comment). |
This PR adds support for the JEE (jakarta inject) annotations to Google Guice, in addition to the existing JSR 330 (javax.inject) and Guice native annotations.
This also adds a new extension module
guice-jakarta-servlet
which supports Servlet API 5.Support is pretty straightforward for annotations; supporting
jakarta.inject.Provider
is a bit trickier. The PR changes the public API of Guice minimally:Visible changes
LinkedBindingBuilder
and its implementations gets a few new methodstoJeeProvider
, similar totoProvider
as the type erasure forClass<? extends javax.inject.Provider>
andClass<? extends jakarta.inject.Provider>
are the same.LinkedBindingBuilder
provides default methods so existing code that implements the interface and its subclasses still work (but they do not support the jakarta annotations right away)SPI Changes
JeeProviderInstanceBinding
andJeeProviderKeyBinding
, analog toProviderInstanceBinding
andProviderKeyBinding
but using the jakarta provider interface.ProviderWithExtensionVisitor
gets an additionalacceptExtensionVisitor
method to supportJeeProviderInstanceBinding
s.BindingTargetVisitor
gets two newvisit
methods to support the new provider bindingsThe code is lightly tested (it works in a medium-size project that now uses a mix of all three injection frameworks (javax.inject, jakarta.inject and native)) and I added some tests.
Known problems
This is still a draft PR, feedback welcome!