Friday, May 14, 2010

Automatic Factories in Unity 2 - Unity 2 Tutorials and Samples
In Unity 2 there is the concept of Automatic Factories to allow classes or services to defer instantiation of their dependencies to the last possible moment. This is particularly useful when the dependency is expensive to create and is not always used by the service. Think of it as lazy loading of dependencies just like we have lazy loading in O/R Mappers.

I mentioned similar functionality in Autofac in the following tutorial: Auto-Generated Factories in Autofac for Lazy Instantiation - LazyDependencyModule. I recommend you read that tutorial as it talks more about the concepts, etc., whereas here I will only mention a few comments and show you an example. Autofac also goes a bit further than Unity 2 by supporting Lazy and Lazy when using Autofac with the .NET Framework 4.

No comments:

Post a Comment