Allow for annotation to replace empty no-args constructor with Inject
See original GitHub issueThere has been a lot of discussion about the no-args @Inject
constructors already. To that end, I would like to propose an alternative solution to the boilerplate-y looking constructor - an annotation that would explicitly mark the class as injectable by Dagger, even without @Inject
marked constructor. Both options could live on, for those who prefer one or another.
Something like this:
import dagger.Injectable;
@Injectable
public class MyService {
// ...
}
If the annotation is present, Dagger would allow for “default” no-args constructor to be used.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
If I use field injection with Guice, why can I only use the no arg ...
So to answer your question, no, it's not possible to request Guice to inject your constructor with a String argument without annotating it...
Read more >@NoArgsConstructor, @RequiredArgsConstructor ...
Overview. This set of 3 annotations generate a constructor that will accept 1 parameter for certain fields, and simply assigns this parameter to...
Read more >Constructor Injection in Spring with Lombok - Baeldung
A constructor doesn't have to be annotated as long as there is only one in a component and Spring can unambiguously choose it...
Read more >Dagger and @Inject on constructors — do or don't?
Now during maintenance when a constructor argument needs added or removed. Not ideal, every change really requires three changes, and let's not ......
Read more >S1186 empty constructor - Google Groups
I'm referring to the use case in which there is more than one constructor and one is no-arg Jax-RS or not. Adding a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I don’t think adding support for something that is so similar to an already standard solution makes sense. Then readers have to discern why one solution was used and not the other. As it is,
@Inject MyService() {}
is just as easy to write, plus it will work with all other JSR 330 injectors.Each new feature adds maintenance cost and conceptual overhead. Some consider it flexibility, others consider it confusing. We’ve opted for fewer concepts unless there’s a clear benefit (runtime, compile time static analysis options, etc). I don’t think this has much benefits besides some personal style.
If we allow custom binding annotations at some point, this would be a great candidate for something that you could add to your project (but keep outside of Dagger).