Part 4. DI Containers

The previous parts of the book have been about the various principles and patterns that together define DI. As chapter 3 explained, a DI CONTAINER is an optional tool that you can use to implement a lot of the general-purpose infrastructure that you would otherwise have to implement if you were using POOR MAN’S DI.

Throughout the book, I’ve strived to keep it as container-agnostic as possible. Don’t interpret this as a recommendation of POOR MAN’S DI; rather, I wanted you to see DI in its pure form, untainted by any particular container’s (possibly quirky) API.

There is little reason to waste your time with POOR MAN’S DI because many excellent DI CONTAINERS are available for .NET. Here in part 4 is a selection of six specific free containers. In each chapter I provide detailed coverage of that particular container’s API as it relates to the dimensions covered in part 3, as well as various other issues that traditionally cause beginners grief.

The containers covered in part 4 are Castle Windsor, StructureMap, Spring.NET, Autofac, Unity, and MEF. There are other container frameworks that I didn’t include for one reason or another: Ninject, Hiro, Funq, LinFu, OCInject, and so on. Please note that inclusion in this book isn’t in itself a seal of approval. Although many of the containers included here are of excellent quality, that wasn’t the only selection criterion. There are certain containers I simply couldn’t exclude because of their market share, whereas I chose to include others because they provide good contrast due to their different design philosophies or purposes. This also means I had to leave out some excellent containers. Given unlimited space, I would have loved to include them all, but alas, that wasn’t possible.

Each chapter follows a common template. This may give you a certain sense of déjà vu as you read the same sentence for the sixth time, but I consider it an advantage because it should enable you to quickly find similar sections across different chapters if you want to compare how a specific feature is addressed across two or more containers. For a quick comparison, refer to this table:

DI CONTAINER

Advantages

Disadvantages

Castle Windsor Complete Understands Decorator Typed factories Commercial support available Quirky API in places
StructureMap Just works in many cases No INTERCEPTION
Spring.NET INTERCEPTION Comprehensive documentation Commercial support available Very XML-centric No convention-based API No custom lifetimes Limited AUTO-WIRING
Autofac Easy to learn API Commercial support available No INTERCEPTION Partial support for custom lifetimes
Unity INTERCEPTION Good documentation Consistent API Poor lifetime management No convention-based API
MEF Available in the .NET 4/Silverlight 4 BCL Commercially supported Not a real DI CONTAINER Configuration based on static attributes No XML support No CODE AS CONFIGURATION No convention-based API No custom lifetimes No INTERCEPTION

Many of the containers described here are open source projects with fast release cycles. The information presented in part 4 was accurate at the time of writing, but always be sure to also consult more up-to-date sources as well.

These chapters are meant as inspiration. If you have yet to pick a favorite DI CONTAINER you can read through all six chapters to compare them all, but you can also just read one or two that particularly interest you.

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

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