Try out Dometrain Pro for FREE with our new 7-day trial!

From Zero to Hero: Dependency Injection in .NET

Master one of .NET's core pillars

It is not an exaggeration to say that Dependency Injection is one of the core pillars of building modern .NET applications. It allows us to write cleaner code, both in structure but also in testability. There is a reason why since .NET Core launched (now simply .NET), it has been part of the framework and part of every codebase that is using it. It is a skill that every single .NET developer needs to master, and in this course, Nick will show you how to do just that.

Curriculum

Welcome

2:34

What will you learn in this course?

1:49

Who is this course for and prerequisites

1:21

The problem with dependencies

6:47

Why Dependency injection is necessary

5:13

A practical example of the dependency problem

10:25

A less obvious example of a Dependency Injection use-case

4:24

Dependency injection benefits past testability

1:11

Injecting Classes vs Abstract classes vs Interfaces

1:51

So do you have to do all that manually??

1:21

Section recap

1:09

Introduction

0:38

The simplest setup with Dependency Injection

6:34

The ServiceCollection

2:00

The ServiceProvider

1:46

All of the above, in an API

5:27

The different types of dependency lifetimes

4:30

The Transient lifetime

2:08

The Singleton lifetime

2:08

The Scoped lifetime

2:31

GetService vs GetRequiredService

3:38

Generic-based registration vs implementation-based registration

3:31

Registration approaches

6:04

The Startup.cs and changes after .NET 6

2:09

Third party libraries

1:49

Section recap

1:09

Resolving dependencies in different project types

0:21

Resolving dependencies from the constructor

0:59

Resolving dependencies from the method

1:27

Resolving dependencies in a console setup

1:17

Resolving dependencies from the HttpContext

1:09

Resolving dependencies from Action Filters as Attributes

2:42

Resolving dependencies from Service Filters

2:42

Resolving dependencies from Middleware

2:32

Resolving dependencies in Minimal APIs

3:13

Resolving dependencies in Razor Views & Pages

1:28

Resolving dependencies in Blazor

1:00

Resolving dependencies in gRPC Services

1:16

Resolving dependencies in Hosted Services

2:38

Resolving dependencies in service registration

1:54

Section recap

0:31

Do you need an interface for everything?

4:59

Choosing the right dependency lifetime

2:31

Dependency resolving issues and limitations

7:43

Registering open generics

2:38

Registering multiple interface implementations

3:22

The ServiceDescriptor

4:22

Add vs TryAdd

4:22

TryAddEnumerable

3:31

Replacing dependencies

5:47

Cleaning up service registration

3:22

Section recap

0:59

Creating a custom scope

5:42

The service locator anti-pattern

2:48

When service locator makes sense

20:37

Avoiding capturing dependencies

3:14

Avoiding multiple service providers

3:18

Creating decorators

7:11

The future of dependency injection

3:55

Section recap

0:47

What is Scrutor?

1:34

Registering service decorators

3:58

Surprise optional refactoring lecture

8:26

Service registration by scanning

13:09

Interface marking

3:28

Attribute marking

3:13

Namespace filtering

2:19

Using the ServiceDescriptor attribute

2:47

Using RegistrationStrategies

2:24

Potential pitfalls

1:52

Section recap

0:46

Why should we even bother?

1:25

The design

2:57

The implementation

19:57

Extending the main implementation

10:36

Section recap

0:33

Conclusion

0:32

Course Info

Level:
From Zero to Hero
Duration:
4h 40m
Rating (3,8K+):
star

Lifetime access

Add to Cart
Dometrain Pro

Want access to all of our courses? Subscribe to Dometrain Pro!

Try it for free!

About the Author

author_img

Nick Chapsas

Nick Chapsas is a .NET & C# content creator, educator and a Microsoft MVP for Developer Technologies with years of experience in Software Engineering and Engineering Management.

He has worked for some of the biggest companies in the world, building systems that served millions of users and tens of thousands of requests per second.

Nick creates free content on YouTube and is the host of the Keep Coding Podcast.

More courses by Nick Chapsas