15 The Microsoft.Extensions.DependencyInjection DI Container

 

In this chapter

  • Working with Microsoft.Extensions.DependencyInjection’s registration API
  • Managing component lifetime
  • Configuring difficult APIs
  • Configuring sequences, Decorators, and Composites

With the introduction of ASP.NET Core, Microsoft introduced its own DI Container, Microsoft.Extensions.DependencyInjection, as part of the Core framework. In this chapter, we shorten that name to MS.DI.

Microsoft built MS.DI to simplify Dependency management for framework and third-party component developers working with ASP.NET Core. Microsoft’s intention was to define a DI Container with a minimal, lowest common denominator feature set that all other DI Containers could conform to.

In this chapter, we’ll give MS.DI the same treatment that we gave Autofac and Simple Injector. You’ll see to which degree MS.DI can be used to apply the principles and patterns laid forth in parts 1–3. Even though MS.DI is integrated in ASP.NET Core, it can also be used separately, which is why, in this chapter, we treat it as such.

15.1 Introducing Microsoft.Extensions.DependencyInjection

15.1.1 Resolving objects

15.1.2 Configuring the ServiceCollection

15.2 Managing lifetime

15.2.1 Configuring Lifestyles

15.2.2 Releasing components

15.3 Registering difficult APIs

15.3.1 Configuring primitive Dependencies

15.3.2 Extracting primitive Dependencies to Parameter Objects

15.3.3 Registering objects with code blocks

15.4 Working with multiple components

15.4.1 Selecting among multiple candidates

15.4.2 Wiring sequences

15.4.3 Wiring Decorators

15.4.4 Wiring Composites

Summary

sitemap