O'Reilly logo

Professional Test-Driven Development with C#: Developing Real World Applications with TDD by Jeff McWherter, James Bender

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

DEPENDENCY INJECTION FRAMEWORKS

If you think of your application as a puzzle, dependency injection (DI) frameworks are the tools that put these puzzle pieces together. Some might even say that dependency injection frameworks are just an implementation of a super factory design pattern. Chapter 5 discussed the basics of dependency injection. The examples used Ninject, but Ninject is not the only dependency injection framework on the market.

In the past, most dependency injection frameworks were configured by using XML files that soon became difficult to maintain. Most modern dependency injection frameworks still support this method of configuration, but this method is generally frowned on and has been traded in for cleaner approaches. This section explores a few alternative dependency injection frameworks using the example from Chapter 5 to inject dependencies into a business application.

When choosing a dependency injection framework, you should follow two rules:

  • Keep the framework at a distance.
  • Focus on the Inversion of Control pattern.

Structure Map

Structure Map is an open source container framework that has a fluent API that makes the code easy to read and maintain. One of the more powerful features of Structure Map is the automocking container.

The Structure Map automocking feature allows you to create stubs automatically when requested by the test. Even though you still need to set your expectations on the mocks, this saves time when you create mocks in your tests.

The ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required