[cdi-dev] Constructor dependency

Sebastian Łaskawiec slaskawi at redhat.com
Tue Jul 7 08:18:44 EDT 2015


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


More information about the cdi-dev mailing list