Allow the easy instantiation of CDI beans
See original GitHub issueDescription
I was wondering if it would make sense to make eager instantiation super easy for users via either an annotation (for per bean control) and / or a config property that would make bean instantation eager by default.
Implementation ideas
We could basically generate the necessary void startup(@Observes StartupEvent event)
under the hood - or perhaps tie deeper into Arc to make this controllable.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:20 (14 by maintainers)
Top Results From Across the Web
How to instantiate more CDI beans for one class?
In Spring there is possible to instantiate any class by defining the corresponding bean in xml conf. It is also possible to instantiate...
Read more >Using CDI Beans in Instantiated Components - Coding Ninjas
CDI Beans are classes that CDI can Automatically instantiate, manage and inject to meet the requirement of the Other objects. CDI can manage...
Read more >Introduction to Contexts and Dependency Injection - Quarkus
There is a simple rule: exactly one bean must be assignable to an injection point, otherwise the build fails. If none is assignable...
Read more >CDI (Part 4): Lazy Initialization - DZone
Let's move onto another big benefit of CDI: lazy initialization. See how and when to implement it in your Java projects with this...
Read more >Weld 2.4.0.CR1 - CDI Reference Implementation
We need to enable an alternative in the beans.xml descriptor of a bean archive to make it available for instantiation and injection. However,...
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
Implementation note: the easiest solution from impl POV would be to introduce an interface, e.g.
StartupCallback
with default no-opstartup()
method and then in the LifecycleEventRunner iterate over all beans that implement this interface and invoke each of the beans.+1 for a
@Startup
annotation. In some classes writing an observer method just to initialize (which does nothing) during the startup is annoying