31 Advanced configuration of ASP.NET Core

 

This chapter covers

  • Building custom middleware
  • Using dependency injection (DI) services in IOptions configuration
  • Replacing the built-in DI container with a third-party container

When you’re building apps with ASP.NET Core, most of your creativity and specialization go into the services and models that make up your business logic and the Razor Pages and APIs that expose them. Eventually, however, you’re likely to find that you can’t quite achieve a desired feature using the components that come out of the box. At that point, you may need to look to more complex uses of the built- in features.

This chapter shows some of the ways you can customize cross-cutting parts of your application, such as your DI container or your middleware pipeline. These approaches are particularly useful if you’re coming from a legacy application or are working on an existing project, and you want to continue to use the patterns and libraries you’re familiar with.

31.1 Customizing your middleware pipeline

31.1.1 Creating simple apps with the Run extension

31.1.2 Branching middleware pipelines with the Map extension

31.1.3 Adding to the pipeline with the Use extension

31.1.4 Building a custom middleware component

31.1.5 Converting middleware into endpoint routing endpoints

31.2 Using DI with OptionsBuilder and IConfigureOptions

31.3 Using a third-party dependency injection container

Summary