Part 3
Pure DI

In chapter 1, we gave a short outline of the three dimensions of DI: Object Composition, Lifetime Management, and Interception. In this part of the book, we’ll explore these dimensions in depth, providing each with their own chapter. Many DI Containers have features that directly relate to these dimensions. Some provide features in all three dimensions, whereas others only support some of them.

Because a DI Container is an optional tool, we feel it’s more important to explain the underlying principles and techniques that containers typically use to implement these features. Given this, part 3 examines how to apply DI without using a DI Container at all. A practical do-it-yourself guide, this is what we call Pure DI.

Chapter 7 explains how to compose objects in various frameworks like ASP.NET Core MVC, Console Applications, and so on. Not all frameworks support DI equally well, and even among those that do, the details differ a lot. For each framework, it can be difficult to identify the Seam that enables DI. Once that Seam is found, however, you have a solution for all applications that use that particular framework. In chapter 7, we’ve done this work for the most common .NET application frameworks. Think of it as a catalog of framework Seams.

Although composing objects isn’t particularly hard with Pure DI, you should begin to see the benefits of a real DI Container after reading about Lifetime Management in chapter 8. It’s possible to properly manage the lifetime of various objects in an object graph, but it requires more custom code than Object Composition. And none of that code adds any particular business value to an application. In addition to explaining the basics of Lifetime Management, chapter 8 also contains a catalog of common lifestyles. This catalog serves as a vocabulary for discussing lifestyles throughout part 4. Although you don’t have to implement any of these by hand, it’s good to know how they work.

The remaining chapters of part 3 explain the last dimension of DI: Interception. In chapter 9, we’ll look at the frequently occurring problem of implementing Cross-Cutting Concerns in a component-based way. We’ll do this by using the Decorator design pattern. Chapter 9 also functions as an introduction to the two chapters following it.

We’ll look at the Aspect-Oriented Programming (AOP) paradigm in chapter 10 and see how a careful application design, based on the SOLID principles, enables you to create highly maintainable code, without the use of any special tooling. We consider this chapter the climax of the book — this is where many readers using the early access program said they began to see the contours of a tremendously powerful way to model software.

Besides applying SOLID design principles, there are other ways to practice Aspect-Oriented Programming. Instead of using patterns and principles, you can use specialized tooling such as compile-time weaving and dynamic Interception tools. These are described in chapter 11.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.54.168