Posts

Showing posts from October, 2018

Dependency injection in C#

What is Dependency Injection? Dependency Injection (DI) is a software design pattern. It allows us to develop loosely-coupled code. How does it do that?  DI reduces the hard-coded dependencies among your classes by injecting those dependencies at runtime/compile time instead of design time technically. Thus it reduces the tight coupling among different software components. It also helps in improving the code readability and testability. Now we know that there quite a lot of advantages using Dependency injection, lets go ahead and identify how many different kinds of Dependency injections are there and how do we go about implementing them. Constructor Injection This is most commonly used dependency injection pattern in object oriented programming. The constructor injection normally has only one parameterized constructor, so in this constructor dependency there is no default constructor and we need to pass the specified value at the time of object creation. We can use the injection