Chapter 14: The Simple Injector DI Container - Dependency Injection

14 The Simple Injector DI Container

In this chapter

  • Working with Simple Injector’s basic registration API
  • Managing component lifetime
  • Configuring difficult APIs
  • Configuring sequences, Decorators, and Composites

In the previous chapter, we looked at the Autofac DI Container, created by Nicholas Blumhardt in 2007. Three years later, Steven created Simple Injector, which we’ll examine in this chapter. We’ll give Simple Injector the same treatment that we gave Autofac in the last chapter. You’ll see how you can use Simple Injector to apply the principles and patterns presented in parts 1–3.

This chapter is divided into four sections. You can read each section independently, though the first section is a prerequisite for the other sections, and the fourth section relies on some methods and classes introduced in the third section. You can read this chapter apart from the rest of the chapters in part 4, specifically to learn about Simple Injector, or you can read it together with the other chapters to compare DI Containers.

Although this chapter isn’t a complete treatment of the Simple Injector container, it gives enough information that you can start using it. This chapter includes information on how to deal with the most common questions that may come up as you use Simple Injector. For more information about this container, see the Simple Injector home page at https://simpleinjector.org.

14.1 Introducing Simple Injector

14.1.1 Resolving objects

14.1.2 Configuring the container

14.2 Managing lifetime

14.2.1 Configuring Lifestyles

14.2.2 Releasing components

14.2.3 Ambient scopes

14.2.4 Diagnosing the container for common lifetime problems

14.3 Registering difficult APIs

14.3.1 Configuring primitive Dependencies

14.3.2 Extracting primitive Dependencies to Parameter Objects

14.3.3 Registering objects with code blocks

14.4 Working with multiple components

14.4.1 Selecting among multiple candidates

14.4.2 Wiring sequences

14.4.3 Wiring Decorators

14.4.4 Wiring Composites

14.4.5 Sequences are streams

Summary

sitemap

Từ khóa » C'vgks