O'Reilly logo

ASP.NET MVC 1.0 Quickly by Maarten Balliauw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dependency injection

Dependency injection is the process of making software components more loosely coupled by injecting dependencies into objects rather than having the object create its own dependencies.

As an example, take the following code:

public class Car
{
private Engine engine;
public Car()
{
engine = new Engine();
}
}

In this example, the Car creates its own dependencies, in this case, a new Engine. It would be a difficult task to unit-test this Car class with a mocked Engine, because there is actually no way to control the dependency of the Car on the Engine. Also, when maintaining this application in the future, inserting other Engine types might be a lot of work and require the refactoring of code.

To solve this issue, the Car class ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required