# 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.

 

 

#Thread Safety Over Static -Tips

1.Are Static class with Static Method Thread Safe ?

Yes,when the static fields/members are of value type.

No when the static fields/members  are of reference type.

2.Are Static Fields inside a non-static method Thread Safe ?

Yes,when the static fields/members are of value type.

No when the static fields/members  are of reference type.

 

 

 

#Areas in MVC

It is hard for maintaining the controllers and views as project grows,

Areas in MVC provides solution by letting you to have controller,model,view per module.

For instance if you have  four modules,you could have four areas with its own controller,model and view.

Capture.PNG
Areas in MVC

In the example above,There are two modules  ExecutiveSponsors and Users put into an area.

Accessing and Configuring the area:

1.You can define the routes for the controller in the Corresponding AreaRegistration.

2.To access the controller from the browser,you must append the area name before the controller.

i.e http: //yourdomainname /Areaname/Controller

Example :

http://localhost:/ExecutiveSponsor/Sample.

 

#oops Basic

  1. You cannot extend or inherit more than 1 abstract class (C# does not provides multiple inheritance.)
  2. Struct cannot implement an abstract class.
  3. Struct can implement interfaces.

class MyClass : a,b ---ERROR--Cannot implement multiple base class.
{

}

abstract class a
{

}

abstract class b
{

}