Monday, August 01, 2011

Can we get a little Unity?

Developers' Hangout Blog - Introduction to Unity Application Block 2.1

“In this post I would like to do a simple introduction to Unity Application Block. Unity is a framework that supports dependency injection (DI) in constructors, properties, and method calls. Unity also supports intercepting method calls which I may cover in a later post.

The documentation for Unity is pretty detailed, so it is probably a good place to start for background information. I’ve also included a link to the download area in the references section at the bottom of the post.

What is Unity and why would you use it?

When you start a project, the code base is usually small so it is not difficult to maintain or test. As the project gets larger, it is often the case that it gets broken down into components, and each component is created separately, and then integrated into the rest of the project.

In the beginning, the components are self contained and testable on their own if the person doing the work was paying attention to object oriented design principles. Even if the component was carefully constructed, at some point during integration it is usually the case that component boundaries begin to break down and components start having strong dependencies on each other.

Part of the break down of component boundaries happens because components start to inherit responsibility for configuring the dependencies with other components. Once a component has built in knowledge on how to create and configure another component, it becomes difficult to separate the components and test them independently.

This is where Unity comes in. Not only does Unity take the responsibility for creating and configuring components, it does so in a consistent way. Components don’t have to know where their dependent components come from. In addition, Unity can automatically create the dependent components if, necessary, or use existing instances.


Been a good while since I’ve blogged about, or [sheepish grin] looked at, Unity so a review of it, what it can do and how it can help use build better apps is timely…


Related Past Post XRef:
IoC? What? Man, I’m just a line of business dev trying to get through my day… What is this inversion of control/IoC, Dependency Injection thing?
Still trying to figure out what DI/IoC but are afraid to speak up?

Writing a MMC Plugin, with MVP and Unity
The Microsoft Patterns & Practices Catalog Cheat Sheet
Microsoft Enterprise Library 5.0 and Unity 2.0 RTW (& EntLib 3.x, 4.x to 5.0, Unity 1.x to 2 Migration Guide)

No comments: