4 ms·
Constructor injection?
by ppcsf 10y ago
Constructor injection?
- chvid 10y agoYes. But then you have to define an explicit constructor. Also X maybe auto wired into ServiceA or B making it impossible for the IoC container to create the intended object graph without splitting construction and injection into two passes.
- yazaddaruvala 10y ago1. Lombok @RequiredArgsConstructor? 2. Do you not consider cyclic dependence a code smell? At least I have always avoided cyclic dependencies.
- chvid 10y agoI personally consider the example I gave as being a nicer way of doing dependency injection than the more verbose constructor based injection. But in general yes; cyclic dependencies are a bad idea.