Dependency Injection in ASP.NET

Posted by Jayakumars under ASP.NET MVC on 11/8/2013 | Points: 10 | Views : 2173 | Status : [Member] [MVP] | Replies : 3
hi
What is Dependency Injection in ASP.NET MVC 4?

Difference B/w 3 tier and this

Mark as Answer if its helpful to you


Responses

Posted by: Bandi on: 11/8/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Dependency Injection Dependency injection is the process of injecting the concrete implementations a class requires rather than the class directly instantiating the dependency. The consuming class is not aware of an actual concrete implementation of any of its dependencies, but knows only of the interfaces that back the dependencies; the concrete implementations are provided either by the consuming class or by a dependency injection framework.

The goal of dependency injection is to create extremely loosely coupled code. The loose coupling lets you easily substitute test double implementations of your dependencies when writing unit tests.

There are three primary ways to accomplish dependency injection:

Property injection
Constructor injection
Using a dependency injection framework/Inversion of Control container (referred to from this point as a DI/IoC framework)


This link gives you detailed explanation about Dependency Injection
http://www.asp.net/mvc/tutorials/hands-on-labs/aspnet-mvc-4-dependency-injection

Refer
http://msdn.microsoft.com/en-us/magazine/jj190803.aspx
http://blogs.msdn.com/b/kirpas/archive/2013/07/30/writing-a-simple-implementation-of-dependency-injection-in-mvc-4-web-api-with-net-framework-4-5.aspx


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 11/8/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
please refer below links :-
http://www.asp.net/mvc/overview/dependency-injection
http://www.asp.net/mvc/tutorials/hands-on-labs/aspnet-mvc-4-dependency-injection
http://www.codeproject.com/Articles/560798/ASP-NET-MVC-Controller-Dependency-Injection-for-Be

differnece between 3 tiers and dependency
http://stackoverflow.com/questions/485519/dependency-injection-in-an-n-tier-application
http://stackoverflow.com/questions/11338297/traditional-3-tier-architecture-vs-3-tier-with-ioc

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 11/8/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Jayakumars,

1. What is Dependency Injection in ASP.NET MVC 4?
In Object Oriented Programming paradigm, objects work together in a collaboration model where there are contributors and consumers. Naturally, this communication model generates dependencies between objects and components, becoming difficult to manage when complexity increases.

You have probably heard about the Factory Pattern and the separation between the interface and the implementation using services, where the client objects are often responsible for service location.

The Dependency Injection pattern is a particular implementation of Inversion of Control. Inversion of Control (IoC) means that objects do not create other objects on which they rely to do their work. Instead, they get the objects that they need from an outside source (for example, an xml configuration file).

Dependency Injection (DI) means that this is done without the object intervention, usually by a framework component that passes constructor parameters and set properties.

The advantages of using Dependency Injection pattern and Inversion of Control are the following:
- Reduces class coupling
- Increases code reusing
- Improves code maintainability
- Improves application testing

Note: Dependency Injection is sometimes compared with Abstract Factory Design Pattern, but there is a slight difference between both approaches. DI has a Framework working behind to solve dependencies by calling the factories and the registered services.

2. Difference between Dependency Injection and 3 tier
For this you can see the below links:-

http://stackoverflow.com/questions/11338297/traditional-3-tier-architecture-vs-3-tier-with-ioc
http://stackoverflow.com/questions/485519/dependency-injection-in-an-n-tier-application
http://stackoverflow.com/questions/13561450/ioc-in-3-tier-architecture

Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response