[cdi-dev] Constructor dependency

Martin Kouba mkouba at redhat.com
Tue Jul 7 08:26:18 EDT 2015

Hi Sebastian,

the "superfluous" constructor is required for client proxies (i.e. for 
normal-scoped beans). Weld may use non-portable JVM APIs that allow to 
allocate proxy instances without this constructor (Unsafe). The feature 
is called "Relaxed construction" [1]. Again, this feature is not portable.



Dne 7.7.2015 v 14:18 Sebastian Łaskawiec napsal(a):
> Hey!
> I've seen CDI 2.0 Early Draft - congratulations! Looks very promising!
> I would like to ask about something slightly different than CDI 2.0 -
> constructor injection. I'm a big fan of using it because I can easily
> inject mocks into tested objects. This way I can limit the number of
> Arquillian tests and speed up testing phase in my project.
> However the drawback is that need 2 constructors in my beans:
> @ApplicationScoped
> public class MyBean {
>       public MyBean() {
>       }
>       @Inject
>       public MyBean(OtherBean bean) {
>       }
> }
> Is it possible to get rid of the zero-parameter constructor? I can
> imagine that it may be required by dependency resolution mechanism (for
> example instantiating beans with cyclic dependencies A -> B -> C -> A),
> but on the other hand we actually can create an instance without calling
> a constructor - using Unsafe (but using Unsafe is always questionable).
> Could you please tell me if there are any plans around this topic?
> Thanks
> Sebastian
> _______________________________________________
> cdi-dev mailing list
> cdi-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/cdi-dev
> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.

Martin Kouba
Software Engineer
Red Hat, Czech Republic

More information about the cdi-dev mailing list