New Guide: Dependency Injection with Unity

imageAbout 20 years ago, Grady Booch, a world renowned software development visionary, stated in his essay Coming of Age in an Object-Oriented World that “our ability to imagine complex applications will always exceed our ability to create them”. Reflecting on this prediction today, we can see how software systems have evolutionarily become more and more complex. One of the techniques for dealing with this inherent complexity of software systems is dependency injection – a design pattern that allows the removal of hard-coded dependencies and makes it possible to assemble a service by changing dependencies easily, whether at run-time or compile-time. It promotes code reuse and loosely-coupled design which leads to more easily maintainable and flexible code.

I’m excited to announce our new guide-primer on using dependency injection with Unity – a lightweight extensible dependency injection container built by the Microsoft patterns & practices team. It covers various styles of dependency injection and also additional capabilities of Unity container, such as object lifetime management, interception, and registration by convention. It also discusses the advanced topics of enhancing Unity with your custom extensions.

The guide contains plenty of trade-off discussions and tips and tricks for managing your application cross-cutting concerns and making the most out of both dependency injection and Unity. These are accompanied by a real world example that will help you master the techniques. Keep in mind that Unity can be used in a wide range of application types such as desktop, web, services, and cloud. I encourage you to experiment with the sample code and think beyond the scenarios discussed in the guide.

In addition, the guide includes the Tales from the Trenches – a collection of case studies that offer a different perspective through the eyes of developers working on the real world projects and sharing their experiences. These chapters make clear the range of scenarios in which you can use Unity, and also highlight its ease of use and flexibility.

Whether you are a seasoned developer or just starting your development journey, we hope this guide will be worth your time studying it. We hope you discover that Unity container adds significant benefits to your applications and helps you to achieve the goals of maintainability, testability, flexibility, and extensibility in your own projects.

Chris Tavares, my colleague and co-creator of Unity, has written the foreword for the guide. Follow his advice:

“I’m thrilled to see this book published. For the first time, there’s one place you can look for both the concepts of DI and how to apply those concepts using the Unity container.  Read the book, embrace the concepts, and enjoy the world of loosely coupled, highly cohesive software that DI makes so easy to build!”

Here’s how to get it:

PDF (free download)

EPUB (free download)

Paperback via Amazon

Kindle edition via Amazon

Comments (17)
  1. Dave Hanson says:

    Cheers for the book, I'm sure it will be very helpful.  

    Just started using Unity again after a long hiatus so this couldn't have come at a better time. 🙂

  2. Tarax says:

    Please get rid of the silly images of people in the book.  Childish.

  3. @Tarax, thank you for checking out the guide and providing your feedback. The face icons are used to denote various personae with the comments to enrich the content. We have been using them for several years now in various guides and only received positive feedback. I'm curious as to what your suggestions might be to us differentiating those call-outs?

  4. SheldonS says:

    If one buys the Kindle edition will updates to the book be pushed out to the Kindle as well?

  5. Sheldon, certainly.


  6. Kevin Rice says:

    Okay, so I too find the face icons a bit corny, but so what? They serve their purpose. Some, like me, prefer a more engineering-like approach… maybe use "CASE EXAMPLE" boxes instead of faces. The faces certainly aren't nearly as good as the timeless "CODING HORROR" guy! =8^O But, really, I don't have time to fret or complain about it. I'm interested in the content. And I'm sure it works well for the masses. Thanks for releasing this knowledge for us!

  7. xabikos says:

    Great book! Thanks

  8. This is a good read, up-to-date with Unity 3.0. However, I would strongly recommend the book by Mark Seemann – Dependency Injection in .Net – which is also mentioned in this guide. Seemanns book is the most comprehensive introduction to DI that I've come across and also contains a chapter on Unity, contrasting Unity with some of the most popular alternatives. Together with this new guide, you should be well on your way to more loosely coupled architectures.

  9. Hal Diggs says:

    absolute cheers for making this a free download!

  10. hussainp says:

    nice book 🙂

  11. Nigel T says:

    Can I make a plea for a document Index in the PDF file?

  12. Dale says:

    It's great to see patterns and practices coming back to the table with how to write better code using Microsoft technologies.  Thanks!

  13. Great read! Thanks for sharing.

  14. jan says:

    dank you

  15. @NigelT

    Book index is there at the very end. Or are you asking specifically for Adobe embedded index?

  16. Rahul tyagi says:

    I am excited to read this and try Unity.

  17. Anthony Desa says:


    Book by Mark Seemann – Dependency Injection in .Net – is definitely a very good book on DI.

Comments are closed.

Skip to main content