Dependency Injection

Learn Dependency Injection techniques along with an IoC-framework (DI-Container). Grow Architecture applying DI.

Last updated 2022-01-10 | 4.2

- Deeply understand the concepts of Dependency Injection and Inversion of Control
- Apply Dependency Inversion Principle (DIP) in practice
- Understand the concept of DI-Containers (IoC-Containers)

What you'll learn

Deeply understand the concepts of Dependency Injection and Inversion of Control
Apply Dependency Inversion Principle (DIP) in practice
Understand the concept of DI-Containers (IoC-Containers)
Build a trivial IoC-Container on your own
Apply existing IoC-Containers (frameworks)
Refactor your code by applying DI coming up with significantly improved Architecture
Write unit tests (this course includes introduction to Unit Testing)
Apply AOP (aspect-oriented programming) techniques

* Requirements

* Some experience in C#

Description

Build a solid foundation in software architecture applying Dependency Injection with IoC-Containers

In many of my courses I use techniques of Dependency Injection and each time students write me private messages saying that they don't what it is and thus they don't understand what's going on in the course I teach. This is very unfortunate from the learning perspectives.

Dependency Injection is the set of techniques that allow to supply dependencies to objects. Actually, if you have ever passed dependencies via constructors, then you applied the so-called constructor injection. Dependency Injection (DI) is simple and difficult at the same time. On one hand, DI is comprised of simple techniques and on the other hand, when we need to bring DI to the next level, we need to make things more complicated using the so-called DI or IoC (Inversion of Control) Containers. These are the frameworks which perform dependency injection automatically. You just need to set one up in the application root (an extremely important notion which you'll learn about in the course) and after that, it will resolve all the dependencies it knows about in the runtime.

If you still don't understand what am I talking about, just believe me, you absolutely need to know about Dependency Injection. This course will tremendously improve your understanding of how software architectures emerge. So, this course is "must watch" for anyone who still doesn't understand what is DI and IoC-Containers.

Content and Overview

This course is aimed at all kind of developers. It provides solid theoretical base reinforced by practical material.   

The course covers:

  • Introduction to Inversion of Control:
    Dependency Inversion Principle (DIP), Inversion of Control (IoC), Dependency Injection (DI),
    Dependencies and their types, Pure DI and IoC-Containers, Service Locator

  • The Architectural Implications of Dependency Injection

  • DI-related Anti-Patterns & Refactorings: 
    Control Freak, Hidden Dependencies, Temporal Coupling,
    Constructor Over-Injection and how to avoid it,
    Ambient Context, Facade Service, Property Injection vs Bastard Injection, Cyclic Dependencies

  • Refactoring Example of an existing code base applying Dependency Injection

  • How to reap the fruits of DI

  • DI-Containers (IoC-Containers):
    Overview, Unity, Late Binding with Unity, Aspect-Oriented Programming (AOP), Interception vs Pure DI vs AOP Tools,

  • Setting up a bootstrapper with Unity, Autofac and Castle.Windsor

  • Introduction to Unit Testing

Teaching Approach

No fluff, no ranting, no beating the air. I respect your time. The course material is succinct, yet comprehensive. All the important concepts are covered. Particularly important topics are covered in-depth.

Take this course, and you will be satisfied. 

Who this course is for:

  • Any C# developer who wants to learn about Dependency Injection and IoC-Frameworks

Course content

9 sections • 86 lectures

How to Ask Questions Preview 00:22

Introduction to Unit Testing Preview 00:11

Download Source Code and Slides Preview 00:03

English Subtitles Preview 00:06

Join .NET Community of Students Preview 00:02

Outline Preview 01:35

The outline of the section dedicated to Dependency Inversion Principle (DIP) and Dependency Injection (DI) where you'll learn the main definitions and concepts.

Definition of DIP Preview 03:30

Learn what is Dependency Inversion Princple (DIP) in essence.

Dependencies Preview 04:49

Learn the definition of a dependency.

Volatile and Stable Dependencies Preview 02:53

Learn the difference between volatile dependencies and stable dependencies.

Definitions of IoC and DI Preview 03:18

Learn what is "inversion of control" and "dependency injection".

DIP Violation Demo Preview 02:47

Look at an example of DIP violation on practice.

Refactoring to a Better Design Applying Dependency Injection Preview 08:31

Look at the refactoring process based on Dependency Injection (DI) that leads to a better design of the application.

Dependency Injection Techniques Preview 07:09

Learn different Dependency Injection (DI) techniques such as Constructor Injection, Property Injection and Method Injection.

Architectural Implications Preview 05:24

Learn about the architectural implications of dependency injection.

Common Smells of DIP Violation Preview 02:37

Learn about the common smells of Dependency Inversion Principle (DIP) violation.

Conclusion Preview 02:03

A conclusion of the section dedicated to Dependency Inversion Principle (DIP) and Dependency Injection (DI). Recap what you learned.

Outline Preview 01:07

Outline of the second section dedicated to DI-Containers (IoC-Containers).

Pure DI and IoC-Containers Preview 05:01

Learn what is Pure DI and how it differs from IoC-Containers (DI-Containers).

Building a Simple IoC-Container Preview 03:53

Learn how to build your own naive implementation of a DI-Container.

Service Locator Design Pattern Preview 02:54

Learn what is Service Locator and how to implement it. What is the difference between a DI-Container and Service Locator?

Demo With an IoC-Container Preview 10:21

Conclusion Preview 01:17

The conclusion for the section on IoC-Containers (DI-Containers). Recap what you learned.

Outline Preview 01:54

The outline of the third section "Dependency Injection - Related Anti-Patterns & Refactorings". Learn what the most common DI-related anti-patterns exist and how to avoid them or how to remove them by applying proper refactorings.

Control Freak Preview 07:06

Learn about the dependency injection anti-pattern called "Control Freak".

Hidden Dependencies with Service Locator Preview 04:41

Learn about the dependency injection anti-pattern called "Hidden Dependencies" that is caused by wrong use of Service Locator design pattern.

Temporal Coupling and Constructor Injection Preview 01:47

Learn about the dependency injection anti-pattern called "Temporal Coupling" and how to avoid it by applying the constructor injection technique.

Constructor Over-Injection Preview 04:05

Learn about the dependency injection anti-pattern called "Constructor Over-Injection" and how to avoid it by applying corresponding refactorings.

Ambient Context Preview 03:53

Learn the Ambient Context design pattern and how to applyt it to avoid the "Constructor Over-Injection" anti-pattern.

Facade Service Preview 02:58

Learn what is Facade Service and how to apply it to avoid constructor over-injection,

Property Injection VS Bastard Injection Preview 03:34

Learn about the dependency injection anti-pattern called "Bastard Injection" and how to cure the decease by applying the property injection.

Cyclic Dependencies Preview 10:50

Learn what is "cyclic dependencies" and why they are pure evil.

Conclusion Preview 02:35

The conclusion on the third section dedicated to DI-related anti-patterns and refactorings.

Outline Preview 01:13

The outline of the fourth section dedicated to analysis of a real-world code example where we apply Dependency Injection to achive loosely coupled code.

Application Overview Preview 01:24

An overview of an application we're going to work on.

Data Access and Models Preview 02:00

Overview of the Data Access Layer.

UI-Side Preview 03:18

In this lecture, I'll demonstrate you the UI-side of the sample application.

The Problem of Tight Coupling Preview 03:41

In this lecture, you'll learn about the problem of tight coupling that can be fixed by Dependency Injection.

Refactoring Process Preview 10:30

In this lecture, you'll learn how to refactor the code base towards loosely-coupled code by applying dependency injection.

Isolating the Bootstrapper Preview 04:20

Learn how to isolate the bootstrapper to adhere to the SRP (Single Responsibility Principle).

Consequences Preview 01:54

Learn what are the consequences of refactoing we performed by applying dependency injection.

Conclusion Preview 01:14

The conclusion on the refactoring of a real-world example by applying dependency injection to achive loosely coupled code.

Outline Preview 00:27

The outline of the fifth section dedicated to harnessing the pros of loosely-coupled code achived through Dependency Injection.

Adding New DAL Preview 08:58

In this lecture, I'll show you how to add new data access layer in a loosely-coupled code that was achieved by applying dependency injection.

Writing Unit Tests for View Models Preview 10:17

In this lecture, you'll see how to write a unit test for a view model in a loosely coupled code achieved by applying dependency injection.

Conclusion Preview 00:45

The conclusion on the section dedicated to harnessing the pros of loosely-coupled code that was achieved by applying dependency injection.

Outline Preview 01:35

The outline of the sixth section dedicated to DI-Containers (IoC-Containers).

Overview of DI-Containers Preview 03:46

Learn what DI-Containers in the world of .NET platforms exist.

Unity DI-Framework Preview 10:17

Learn how to build a bootstrapper with a Unity DI-Containe.

Late Binding with Unity Preview 05:30

Learn what is late binding and how to implement it with Unity.

Aspect-Oriented Programming (AOP) Preview 03:49

Learn what is Aspect-Oriented Programmin or AOP in short.

Demonstration of the Problem of Boilerplate Code Preview 04:08

Look at the problem of the boilerplate code that can be solved by AOP.

Implementing AOP by Intercepting Preview 05:19

Learn how to apply AOP by using the power of Intercepting feature of Unity.

Interception vs Pure DI vs AOP Tooling Preview 02:40

Learn the pros and cons of different approaches to implement AOP.

Autofac and Castle.Windsor DI-Containers Preview 04:29

Learn how to build a bootstrapper with Autofac and Castle.Windsor DI-Containers.

Problems Related to DI-Containers Preview 01:57

Learn what the problems are related to DI-Containers.

Conclusion Preview 00:57

The conclusion on the sixth section dedicated to DI-Containers (IoC-Containers).

BONUS Lecture Preview 01:18

Outline Preview 00:58

What is a Unit Test Preview 03:09

Unit Testing Frameworks Preview 03:22

Your First Unit Test Preview 08:43

Naming Conventions Preview 04:34

Running and Debugging Unit Tests Preview 05:02

Benefits of Unit Tests Preview 03:35

Who Should Write Unit Tests and When Preview 02:51

Programmer's Oath Preview 03:17

Exercise: Degree Converter Preview 01:29

Solution: Degree Converter Preview 06:54

Conclusion Preview 01:15

Outline Preview 01:01

Assert Intro Preview 05:29

Assert Demo Preview 10:27

Arrange-Act-Assert Preview 00:58

Running Tests from the Console Preview 01:51

SetUp and TearDown Preview 05:09

OneTimeSetUp and OneTimeTearDown Preview 02:13

Parameterized Unit Tests Preview 03:40

Grouping and Ignoring Unit Tests Preview 02:14

Code Coverage Preview 01:42

Exercise: FizzBuzz Preview 01:07

Solution: FizzBuzz Preview 05:05

Exercise: Parsing Roman Numerals Preview 02:27

Solution: Parsing Roman Numerals Preview 09:27

Exercise: Stack Preview 00:59

Solution: Stack Preview 09:02

Conclusion Preview 01:25