1 of 1 people found this helpful
Yes, I think having this as a feature would be nice. I'd prefer having an extra annotation @LazySingleton as you suggested. However, simply skipping the addBean() call won't do it because this call just registers the bean with the BeanManager. We would have to find a way to delay the call to getInstance() in the Bootstrapper until the bean is actually used. Until it is either injected into a non-lazily loaded bean (in that case @LazySingleton would behave exactly like @Singleton), or into another lazily loaded bean that was just created or until it is being looked up using the BeanManager API.
Of course, you're more than welcome to take a stab at it / create a JIRA if you're interested!
thanks for your answer and the hints regarding an implementation.
We already have already started implementing lazy singletons in our app using the @LazySingleton Annotation.
The next weeks we will finish and test this implementation in our app. But its looking good so far. When we think its finished we can make a pull request.
We will do so eventually when we face to much merge conflicts with the main errai branch
What about such singleton with lazy loading in errai v3.1.2 ?
Anyone know if this was progressed?
In Errai 4, @Singleton and @ApplicationScoped beans are no longer instantiated before they are injected somewhere. Furthermore, @ApplicationScoped beans behave as in Weld: they are proxied by the container and are not actually instantiated until a method is invoked.