CHAPTER 9

image

Dependency Injection

This chapter covers dealing with dependency injection in Web API services. You will learn how to do the following:

  • Inject dependencies into Web API controllers, filters, message handlers, and formatters (Recipe 9-1 and 9-4)
  • Add support for the common DI containers (Recipe 9-2)
  • Deal with per-request dependency scope (Recipe 9-3)
  • Write a custom dependency resolver for ASP.NET Web API applications (Recipe 9-5)

9-1. Inject Dependencies into ASP.NET Web API Controllers

Problem

You would like to inject, through the constructor, dependencies into your ASP.NET Web API controllers.

Solution

ASP.NET Web API provides two primary ...

Get ASP.NET Web API 2 Recipes: A Problem Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.