-
Notifications
You must be signed in to change notification settings - Fork 77
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
More convenient injection into Java records #832
Comments
Decorated beans are implemented through subclassing, just like intercepted beans, so this would not really work.
|
When using record type, I must add a cocanial constructor and an extra
|
This seems doable, just a few thoughts:
Not sure what you mean here. The injection into records would need to be through constructors only - all other parts are by definition |
What I said here is that when a record class is annotated with |
I see, that's a little different from what I meant in my previous comment and would require us to special case records for sure. |
This is Java the language decision. They simply don't provide a way to annotate the constructor without actually declaring it. I don't see why CDI / AtInject should try to fix that "problem". |
I think the only reason is just convenience. Special casing records is IMO not worth it. Now, I might have missed something but so far I can't think of anything preventing us from doing this. |
Historically with a discovery mode of "all" this could cause a lot of beans to exist. I (very dimly) seem to recall in the earliest days of the specification people deciding this was a bad idea. Maybe that's no longer a relevant situation/case; I don't know. |
Hm, that's a fair point, thanks for mentioning that. |
But with the new default mode of needing a bean defining annotation, it would only pick up classes that someone was trying to use a bean. To date no class with a non-default ctor could in fact be a bean, so the impact of this should tend to zero. |
The I guess we could further tweak the suggestion in my previous comment and state that this only works for class-based beans that have a bean defining annotation on them? |
Seriously, is @Dependent
public record Foo(Bar bar) {
@Inject
Foo {
}
} so much worse than @Dependent
public record Foo(Bar bar) {
} ? |
CDI
@Singleton
bean and@Decorator
do not generate proxy at runtime, it should allow it to be declared as a record type. And inject dependent beans via constructor injection.The text was updated successfully, but these errors were encountered: