Daniel Cazzulino's Blog

Go Back to
kzu′s Latest post

Funq: screencast series on how to build a DI container using TDD

Over the past few days, I spent some time recording the experience of building a dependency injection container using test driven development. It was a cool experience for me, and I hope you find the screencasts useful.

Here are all the episode links:

  1. Part I: selecting a high performance approach and building the basics with few lines of code. View | Download
  2. Part II: adding support for passing constructor arguments to resolved instances. View | Download
  3. Part III: adding named services and refactoring to improve code. View | Download
  4. Part IV: add support for instance reuse. View | Download
  5. Part V: adding support for container hierarchies. View | Download
  6. Part VI: adding deterministic disposal of container hierarchies and instances created by them. View | Download
  7. Part VII: polishing a fluent API. View | Download
  8. Part VIII: adding support for initializer functions. View | Download
  9. Part IX: how well does it perform really? View | Download


Funq is by no means a revolutionary concept to DI, I’m well aware of that. But it’s one that takes a minimalistic approach to keep the performance impact of DI to a bare minimum. One of the project core requirements was to perform very well on the Compact Framework, as part of its inclusion in the upcoming Mobile Client Software Factory v2 from patterns & practices.

I hope this series serves to understand the inner workings of this fully functional yet extremely simple DI container.


[Update 3/10/2011]: I’ve been told these videos are being used also to showcase how to do TDD in a real-world scenario, which is quite gratifying. And I’ve just checked Amazon Cloud Front (which I use to make the downloads available to you at the fastest possible speeds without breaking the bank) and it’s still consistently delivering ~4GB/month of downloads across the globe (top EU, then USA).

[Update 3/25/2015]: Moved all videos to YouTube since now they can be high-res unlike back then :) . Created a playlist, but kept the original download locations.

Here is the whole series as a YouTube playlist:



  1. This is a great series so far (just finishing part 2). However, I do have a nit to pick. This is not truly TDD, but unit testing.

  2. How is it not TDD? I’m driving the API and the features from what the tests and the intended behavior dictate… no? (I may have gotten ahead a few times, but I’m pretty sure I did it in true TDD fashion…)

  3. In part I, when you change the API so that a factory can get dependencies injected (Func), you decided to change the first unit test, so that it didn’t break with the new change, but in my opinion, you should have refactored the API implementation so it didn’t break the previous test, and also pass the new test, like so:
    public void Register(Func factory)
    Func cFactory = c => factory.Invoke();
    // Simply call the new method

    public void Register(Func factory)
    this.factories.Add(typeof(TService), factory);

  4. public void Register<TService>(Func<TService> factory)
        Func&ltContainer, TService> cFactory = c => factory.Invoke();
    // Simply call the new method

    public void Register<TService>(Func<Container, TService> factory)
        this.factories.Add(typeof(TService), factory);

  5. Evolving APIs and breaking existing test because older API doesn’t make sense anymore, does not go against TDD. There’s nothing wrong with doing so.

  6. It makes sense when you have a lot of code that already uses the previous API. And, I think it does make sense to have the ability to register a type that doesn’t need dependencies, without having to specify unneeded parameters.

    • A very valid personal preference. In this case, there was NO existing code, and I made a design choice. How does any of that goes against TDD, I still don’t get it…

  7. Hahaha, hey, I’m not the guy that said that’s against TDD, I’m just saying I would make those design choices, and felt like that alternative should be pointed out.

  8. I could not get access to the videos, the links are broken, Any help?

  9. Fixed. The only broken links where the Download ones. You can still view the videos straight from viddler.


  10. Hi,
    The download and the viddler links are both broken… looking forward to viewing these.


  11. [...] Funq: screencast series on how to build a DI container using TDD – Daniel Cazzulino’s Bl… – [...]

  12. Why have you not pursued further development on Funq, everywhere everyone is saying that the code base hasn’t been upgraded since 2009.

    Is that true or is there a new code base that is under active development even today ?

  13. Great videos! Do you still have your DI performance application source code on the web somewhere. I think in video #1 you said the source could be found on google code, but I don’t see any links for it anywhere.

  14. Hi Daniel,

    These videos are great. I am new to TDD and it’s refreshing to see some decent resources to learn from – ones that actually show the process in action.


  15. Hi,

    Thanks for this excellent material. Unfortunately the videos seem to be gone from Direct download links are still working.