From the course: ASP.NET Core: Test-Driven Development

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Dependency injection and IoC

Dependency injection and IoC - ASP.NET Core Tutorial

From the course: ASP.NET Core: Test-Driven Development

Start my 1-month free trial

Dependency injection and IoC

- [Instructor] Before we go into some TDD examples, I'd like to go over some key components that will help you understand how to write testable code. Dependency Injection a key component to writing clean, testable code. Not only does it let you separate your classes of responsibilities better, but when you do it properly it can also make writing your code easier too. Now you'll often hear the terms Dependency Injection and Inversion of Control used together. They're usually shortened to DI and IoC. Let's talk a little bit about what these terms mean and then we'll go over some examples. IoC is a design principle. It basically states that your framework should be responsible for creating and calling your classes. Dependency Injection is a design pattern where your classes are provided the dependencies they need to run. Dependency Injection is actually a form of IoC. Here we have an MVC controller called HomeController. All it does is log a message before returning a view. But I'd like…

Contents