Unity 2 and Enterprise Library 5 will hopefully be released in April or May just after Visual Studio 2010 is released. Two new features of Unity 2 that I have recently been playing with are Automatic Factories and InjectionFactory.
InjectionFactory in Unity
Unity's new InjectionFactory is essentially a replacement for the StaticFactoryExtension and then some. The StaticFactoryExtension allowed you to register a factory method to create an object when using UnityContainer.Resolve. That was okay, but it was extremely overkill when a simple lambda expression or anonymous delegate would have fit the bill.
With InjectionFactory you get a much more elegant interface. For an example of InjectionFactory, please see the following tutorial:
Automatic Factories in Unity
Automatic Factories in Unity is another nice feature. Often your classes have dependencies that are often expensive to create and possibly optional depending on the context of the request. In these cases, you don't want Unity to create an instance of the dependency, but rather provide you a Func<T> that you can invoke to create the dependency only at the point it is really needed.
Automatic Factories provide you this lazy load type of functionality for free. For a good example of using Automatic Factories in Unity 2, check out the followin tutorial:
Conclusion
In the next month or so I will start to publish some Unity 2 and Enterprise Library 5 screencasts. If you live in Florida, I am kicking off some presentations on Enterprise Library 5 and Unity 2 as well.
Hope this helps.
David Hayden
Related Posts: