# Dealing with Constructor-Over InJection-Part 1

What is constructor-over Injection ?

while constructor-injection is the most common way to resolve the dependency,there are cases where design of improper system such as violating the SOLID  would lead to have many dependency getting loaded in the constructor.

Example :

public class SampleClass


public SampleClass(IDependency1 Dependency1 ,IDependency2 Dependency2 ,,IDependency3 Dependency3 ,IDependency4 Dependency4 ,,IDependency5 Dependency5 ,IDependency6 Dependency6 )


//Constructor Over injected as you need 6 Dependency to be resolved when you create instance of SampleClass.



In the above example to create the instance of SampleClass,it requires 6 Dependency to get resolved.

The above code clearly indicates the following

1.we have violated the SOLID principles,mainly the single responsibility principle,the sample class listed is clearly doing more than one thing.

2.Improper Design of classes.

How to deal with Constructor Over Injection :

Facade Services : You apply the Facade pattern and decompose the constructor arguments as many  as possible.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s