30% OFF - Use code HANDSON30 for 30% off any course or Dometrain Pro! Browse courses →
  • Courses
  • Learning Paths
  • Blogs
  • Authors
  • Leaderboard
  • Dometrain Pro
  • Shopping Basket

    Your basket is empty

  • Business Portal
  • From Zero to Hero: Dependency Injection in .NET with C#

    Master Dependency Injection in .NET with this comprehensive course by Nick Chapsas. Learn how to build cleaner, more maintainable code, optimize testability, and tackle real-world projects.

    About This Course

    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.

    Course Curriculum

    4h 41m 9 sections
    Welcome
    02:34 Free preview
    What will you learn in this course?
    01:49 Free preview
    Who is this course for and prerequisites
    01:21 Free preview
    The problem with dependencies
    06:47
    Why Dependency injection is necessary
    05:13
    A practical example of the dependency problem
    10:25
    A less obvious example of a Dependency Injection use-case
    04:24
    Dependency injection benefits past testability
    01:11
    Injecting Classes vs Abstract classes vs Interfaces
    01:51
    So do you have to do all that manually??
    01:21
    Section recap
    01:09
    Introduction
    00:38
    The simplest setup with Dependency Injection
    06:34
    The ServiceCollection
    02:00
    The ServiceProvider
    01:46
    All of the above, in an API
    05:27
    The different types of dependency lifetimes
    04:30
    The Transient lifetime
    02:08
    The Singleton lifetime
    02:08
    The Scoped lifetime
    02:31
    GetService vs GetRequiredService
    03:38
    Generic-based registration vs implementation-based registration
    03:31
    Registration approaches
    06:04
    The Startup.cs and changes after .NET 6
    02:09
    Third party libraries
    01:49
    Section recap
    01:09
    Resolving dependencies in different project types
    00:21
    Resolving dependencies from the constructor
    00:59
    Resolving dependencies from the method
    01:27
    Resolving dependencies in a console setup
    01:17
    Resolving dependencies from the HttpContext
    01:09
    Resolving dependencies from Action Filters as Attributes
    02:42
    Resolving dependencies from Service Filters
    02:42
    Resolving dependencies from Middleware
    02:32
    Resolving dependencies in Minimal APIs
    03:13
    Resolving dependencies in Razor Views & Pages
    01:28
    Resolving dependencies in Blazor
    01:00
    Resolving dependencies in gRPC Services
    01:16
    Resolving dependencies in Hosted Services
    02:38
    Resolving dependencies in service registration
    01:54
    Section recap
    00:31
    Do you need an interface for everything?
    04:59
    Choosing the right dependency lifetime
    02:31
    Dependency resolving issues and limitations
    07:43
    Registering open generics
    02:38
    Registering multiple interface implementations
    03:22
    The ServiceDescriptor
    04:22
    Add vs TryAdd
    04:22
    TryAddEnumerable
    03:31
    Replacing dependencies
    05:47
    Cleaning up service registration
    03:22
    Section recap
    00:59
    Creating a custom scope
    05:42
    The service locator anti-pattern
    02:48
    When service locator makes sense
    20:37
    Avoiding capturing dependencies
    03:14
    Avoiding multiple service providers
    03:18
    Creating decorators
    07:11
    The future of dependency injection
    03:55
    Section recap
    00:47
    What is Scrutor?
    01:34
    Registering service decorators
    03:58
    Surprise optional refactoring lecture
    08:26
    Service registration by scanning
    13:09
    Interface marking
    03:28
    Attribute marking
    03:13
    Namespace filtering
    02:19
    Using the ServiceDescriptor attribute
    02:47
    Using RegistrationStrategies
    02:24
    Potential pitfalls
    01:52
    Section recap
    00:46
    Why should we even bother?
    01:25
    The design
    02:57
    The implementation
    19:57
    Extending the main implementation
    10:36
    Section recap
    00:33
    Course conclusion
    00:32

    Meet Your Instructor

    Nick Chapsas

    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.

    View all courses by Nick Chapsas

    What's New

    Getting Started: Model Context Protocol (MCP)
    course

    Getting Started: Model Context Protocol (MCP)

    Learn how to get started with the Model Context Protocol (MCP) and integrate it into your applications.

    Learn more about Getting Started: Model Context Protocol (MCP)
    Hands-On: Learn TypeScript
    course

    Hands-On: Learn TypeScript

    Learn TypeScript through hands-on coding exercises. Practice what you learn with interactive challenges designed for every level.

    Learn more about Hands-On: Learn TypeScript
    Hands-On: Learn JavaScript
    course

    Hands-On: Learn JavaScript

    Learn JavaScript through hands-on coding exercises. Practice what you learn with interactive challenges designed for every level.

    Learn more about Hands-On: Learn JavaScript
    Hands-On: Data Structures & Algorithms in C#
    course

    Hands-On: Data Structures & Algorithms in C#

    Master data structures and algorithms through hands-on coding exercises in C#. Free to enroll for 7 days!

    Learn more about Hands-On: Data Structures & Algorithms in C#
    Blogsmith.ai
    feature

    Blogsmith.ai

    Turn your videos into blogs and newsletters with AI. Check out our new product at blogsmith.ai.

    Learn more about Blogsmith.ai
    Leaderboard
    feature

    Leaderboard

    See how you stack up against other learners. Track your progress, climb the ranks, and compete with the Dometrain community.

    Learn more about Leaderboard
    Hands-On: Learn PostgreSQL
    course

    Hands-On: Learn PostgreSQL

    Learn PostgreSQL through hands-on coding exercises. Practice what you learn with interactive challenges designed for every level.

    Learn more about Hands-On: Learn PostgreSQL
    Free Hands-On: C# for Beginners
    course

    Free Hands-On: C# for Beginners

    Learn C# through hands-on coding exercises. Practice what you learn with interactive challenges designed for everyone, from beginners to experts.

    Learn more about Free Hands-On: C# for Beginners
    Getting Started: AI for .NET Developers
    course

    Getting Started: AI for .NET Developers

    Get started with integrating AI into your .NET applications effectively using the latest LLM best practices.

    Learn more about Getting Started: AI for .NET Developers
    Getting Started: Building .NET Applications on AWS
    course

    Getting Started: Building .NET Applications on AWS

    Learn how to build and deploy .NET applications on AWS using CDK, Lambda, DynamoDB, S3, and more.

    Learn more about Getting Started: Building .NET Applications on AWS
    What's new in C# 14
    blog

    What's new in C# 14

    This guide covers every new C# 14 feature, explains its benefits, and provides practical code examples to help you navigate how you can use them.

    Learn more about What's new in C# 14
    Let's Build It: AI Chatbot with RAG in .NET Using Your Data
    course

    Let's Build It: AI Chatbot with RAG in .NET Using Your Data

    Build a Retrieval-Augmented Generation (RAG) chatbot that can answer questions using your data.

    Learn more about Let's Build It: AI Chatbot with RAG in .NET Using Your Data
    From Zero to Hero: SignalR in .NET
    course

    From Zero to Hero: SignalR in .NET

    Enable enterprise-grade real-time communication for your web apps with SignalR.

    Learn more about From Zero to Hero: SignalR in .NET
    Deep Dive: Solution Architecture
    course

    Deep Dive: Solution Architecture

    Master solution architecture and turn business needs into scalable, maintainable systems.

    Learn more about Deep Dive: Solution Architecture
    Migrating: ASP.NET Web APIs to ASP.NET Core
    course

    Migrating: ASP.NET Web APIs to ASP.NET Core

    A step-by-step process to migrate ASP.NET Web APIs from .NET Framework to ASP.NET Core.

    Learn more about Migrating: ASP.NET Web APIs to ASP.NET Core
    Getting Started: Caching in .NET
    course

    Getting Started: Caching in .NET

    Let's make the hardest thing in programming easy for .NET software engineers.

    Learn more about Getting Started: Caching in .NET
    From Zero to Hero: Testing with xUnit in C#
    course

    From Zero to Hero: Testing with xUnit in C#

    Learn how to test any codebase in .NET with the latest version of xUnit, the industry-standard testing library.

    Learn more about From Zero to Hero: Testing with xUnit in C#
    Create a ChatGPT Console AI Chatbot in C#
    blog

    Create a ChatGPT Console AI Chatbot in C#

    This walkthrough is your hands-on entry point to create a basic C# console application that talks to ChatGPT using the OpenAI API.

    Learn more about Create a ChatGPT Console AI Chatbot in C#