Rob Smyth

Monday, 3 September 2007

.Net Dependency Injection Frameworks - Part 1

In recent work I have been finding dependency injection (Inversion of Control, IoC) very helpful to enable TDD. While in early development object assembly was relatively simple it is now becoming more complex making me think more about using an IoC framework. This post documents my progress in looking at frameworks and I hope will be updated as I learn more.

The nature of the application is that it will have a long lifetime and will need to be expandable. Overall project complexity is medium.

Requirements:
  • .Net C#
  • License suitable for commercial use
  • Require constructor injection (for readability) and setter injection to support circular dependencies
  • Runtime creation of object sets
  • Plugin support ... I'm not sure
  • Suitable use in a TDD environment with mocking
  • Code readability and simplicity

Spring.Net

The documentation introduction starts by describing Spring as being for 'enterprise applications' and goes on to talk about much more than IoC. So my first impression is that this may be too heavy for my liking.

StructureMap

A dependency injection framework, nothing else. This I like.

I've done a quick look at the documentation. My first impression is good. I noticed a feature suggesting support for mocked object injection. I've not looked further but this is interesting as I do spend time most days creating mock objects for injection.

MicroKernel

First glance is good. Looks simple to use. I want to come back to this one later for a closer look.

ObjectBuilder

The documentation page shows 'under construction ...'. Not a good sign. The site was not first time visitor friendly so I reckon I will revisit this one only if I get desperate.

PicoContainer .Net

Nice documentation, looks cool, but it is really focused on Java. I get the feel that while .Net code is available it isn't really a prime focus. So I will skip this one.

Puzzle.Net

Looks interesting but difficult to find documentation. I noticed another project NPersist on the site that I want to look at later. This one is worth another look later.

Ninject

Looks real good for what I'm looking for. Lightweight. It uses a service binding concept so I need to check if a single interface can be 'bound' to different implementations for different targets.

Links:

No comments: