Dotnet logo

The .NET Tools Blog

Essential productivity kit for .NET developers

.NET Tools Webinars

.NET 5 Dependency Injection – Webinar recording

The recording of our webinar, .NET 5 Dependency Injection, with Steve CollinsSubscribe to our community newsletter to receive notifications about future webinars.


Since the release of .NET Core (now.NET 5), more developers are making use of dependency injection by using the default Microsoft Dependency Injection container that comes out of the box with .NET Core. This default implementation is sometimes limited in what it can do when compared to the features found in other containers available for the platform. In addition, there are some pain points that you may encounter if you have not read all of the documentation.

This talk will take you beyond the basics of the Microsoft container and covers more complex topics such as:

  • Explaining the limitations of the default container
  • Integrating with other DI containers
  • Perceived conflicts between service lifetimes
  • Understanding the Root and Scoped service providers used with different lifetimes
  • Thread safety and avoiding memory leaks, particularly with Singletons
  • Understanding deliberate and unintended multiple registrations
  • Registering and resolving classes with multiple interfaces
  • Registering and resolving multiple class implementations of a single interface
  • Registering and resolving open generics
  • Keyed and named registrations are not supported … but I need it!
  • How traditional design patterns such as Factory, Builder and Decorator can be integrated
  • Using delegate functions over OOP interfaces and classes
  • Automated service registration


Webinar agenda:

  • 0:00 – Introduction
  • 1:15 – .NET 5 Dependency Injection refresher
  • 9:48 – Service Lifetimes
  • 13:03 – When to use a singleton?
  • 17:20 – Transient dependencies
  • 17:49 – Scoped dependencies
  • 28:09 – Handling disposables
  • 31:15 – Common mistakes
  • 33:39 – Handy tips and tricks
  • 33:44 – Deliberate multiple registrations
  • 35:28 – Same class, many interfaces
  • 36:37 – Open generics
  • 38:32 – Constrained generics
  • 39:35 – Design patterns
  • 47:27 – Working around limitations
  • 48:00 – Registering value types
  • 49:20 – Registering C# 9 records
  • 50:21 – Register delegates instead of interfaces
  • 53:26 – Named and keyed dependencies
  • 57:01 – Decorator pattern
  • 59:32 – Summary
  • 1:02:32 – Q&A

Resources:

Download Rider and give it a try!

About the presenter:

Steve Collins
Steve Collins is an independent software developer with over 25 years’ experience in the industry working with Microsoft technologies.

Steve has been giving talks in person and virtually to user groups and community conferences around the UK, focusing on his pet subjects of Dependency Injection and Configuration in .NET.

Steve blogs at https://SteveTalksCode.co.uk.

Follow Steve on Twitter.

Discover more