Tuesday, March 6, 2018

Drawback of Property Injection

1.One of the drawback of  property injection is that it does not ensures dependency Injection. You can not guarantee that certain dependency is injected or not, which means you may have an object with incomplete dependency. On other hand constructor Injection does not allow you to construct object, until your dependencies are ready.

2. Constructor injection enforces the order of initialization and prevent circular dependencies while in case of property injection it is not clear in which order things need to be instantiated.

3. By using setter injection, you can override certain dependency which is not possible with constructor injection because every time you call the constructor, a new object is gets created.

4. If Object A and B are dependent each other i.e A is depends ob B and vice-versa. You can  not create both object bcz A object cannot be created until B is created and vice-versa. This (circular dependencies ) can be resolve through property-injection. Objects constructed before property invoked.

No comments: