Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdi-dev] Regarding annotations

Hello,

I am from Weld, so no need to take this elsewhere just yet :)

What Tomas Langer said is right - according to CDI specification, Singleton is not a bean defining annotation and as such won't trigger discovery in default settings.
So the behavior is correct, albeit somewhat weird. See this part of CDI specification - https://jakarta.ee/specifications/cdi/2.0/cdi-spec-2.0.html#bean_defining_annotations
The important bit is that @Singleton is not a normal scope type.

However, Weld offers the ability to expand bean defining annotations in SE container, see this Weld document piece - https://docs.jboss.org/weld/reference/latest/en-US/html_single/#_extending_bean_defining_annotations
If memory serves, Helidon uses Weld SE, so they could do just that (and probably did).

I would be -1 to remove Singleton, I see it used pretty commonly. The main difference from app scoped is that while they are both "one instance per container", application scope uses proxies, whereas singleton doesn't.
This usually doesn't matter, but there are cases (more prominent in build time environment, or when it comes to serialization, or where you want lazy init, ...) in which the difference matters and being able to choose is nice.
If anything, I would rather add Singleton as a bean defining annotation into CDI.

Hope this helps
Matej

----- Original Message -----
> From: "Abhideep Chakravarty" <abhideepchakravarty@xxxxxxxxx>
> To: "cdi developer discussions" <cdi-dev@xxxxxxxxxxx>
> Sent: Monday, December 14, 2020 3:37:25 PM
> Subject: Re: [cdi-dev] Regarding annotations
> 
> Helidon is using WELD 3.1.4. In that case, I would have go and talk to WELD.
> 
> On Mon, Dec 14, 2020 at 3:33 PM Emily Jiang < emijiang6@xxxxxxxxxxxxxx >
> wrote:
> 
> 
> 
> I don't see why @Singleton is not supported since it is part of JSR 330,
> which is supported by CDI. You should raise this with the Helidon project.
> Thanks
> Emily
> 
> On Mon, Dec 14, 2020 at 1:02 AM Abhideep Chakravarty <
> abhideepchakravarty@xxxxxxxxx > wrote:
> 
> 
> 
> Hi team,
> 
> I have recently migrated to Helidon from classic EE application. One problem
> I faced there was that the CDI stopped working. After getting some help, I
> was suggested to replace @Singleton with @ApplicationScoped. Once that's
> done things started working.
> 
> I was discussing the same with Reza Rehman a day back after seeing his news
> letter on Jakarta EE 10. He suggests not to use Singleton unless it's
> absolutely necessary.
> 
> Here is my concern:
> If we have more than one option for doing same thing and other than one
> option everything else comes with 'use it if it's absolutely necessary' tag,
> then why don't we just remove those extra things and keep the one which is
> best to use. If we can remove in one shot, let's deprecate them.
> 
> Can we ?
> 
> 
> Regards,
> Abhideep
> _______________________________________________
> cdi-dev mailing list
> cdi-dev@xxxxxxxxxxx
> To unsubscribe from this list, visit
> https://www.eclipse.org/mailman/listinfo/cdi-dev
> 
> 
> --
> Thanks
> Emily
> 
> _______________________________________________
> cdi-dev mailing list
> cdi-dev@xxxxxxxxxxx
> To unsubscribe from this list, visit
> https://www.eclipse.org/mailman/listinfo/cdi-dev
> 
> _______________________________________________
> cdi-dev mailing list
> cdi-dev@xxxxxxxxxxx
> To unsubscribe from this list, visit
> https://www.eclipse.org/mailman/listinfo/cdi-dev
> 



Back to the top