8 Object lifetime

 

In this chapter

  • Managing Dependency Lifetime
  • Working with disposable Dependencies
  • Using Singleton, Transient, and Scoped Lifestyles
  • Preventing or fixing bad Lifestyle choices

The passing of time has a profound effect on most food and drink, but the consequences vary. Personally, we find 12-month-old Gruyère more interesting than 6-month-old Gruyère, but Mark prefers his asparagus fresher than either of those.1  In many cases, it’s easy to assess the proper age of an item; but in certain cases, doing so becomes complex. This is most notable when it comes to wine (see figure 8.1).

Wines tend to get better with age—until they suddenly become too old and lose most of their flavor. This depends on many factors, including the origin and vintage of the wine. Although wines interest us, we don’t ever expect we’ll be able to predict when a wine will peak. For that, we rely on experts: books at home and sommeliers at restaurants. They understand wines better than we do, so we happily let them take control.

Figure 8.1 Wine, cheese, and asparagus. Although the combination may be a bit off, their age greatly affects their overall qualities.
08-01.tif

8.1 Managing Dependency Lifetime

8.1.1 Introducing Lifetime Management

8.1.2 Managing lifetime with Pure DI

8.2 Working with disposable Dependencies

8.2.1 Consuming disposable Dependencies

8.2.2 Managing disposable Dependencies

8.3 Lifestyle catalog

8.3.1 The Singleton Lifestyle

8.3.2 The Transient Lifestyle

8.3.3 The Scoped Lifestyle

8.4 Bad Lifestyle choices

8.4.1 Captive Dependencies

8.4.2 Using Leaky Abstractions to leak Lifestyle choices to consumers

8.4.3 Causing concurrency bugs by tying instances to the lifetime of a thread

Summary

sitemap