Tuesday, October 19, 2010

Speed up your Unity Container!

The Unity Application Block (Unity) http://www.codeplex.com/unity is a lightweight extensible dependency injection container with support for constructor, property, and method call injection.
Unity offers supports 3 types of injection: Property, Constructor and Method Injection.
If you are prepared to trade Property and Method Injection for better performance... then continue reading. I will describe in simple steps how to disable Property and Method Injection.
Sadly you will need to comment out 4 lines from the Unity sources and recompile. I hope someday the Unity dev team provides the possibility to specify what types of injections your container should support upon container creation.

Step 1: UnityDefaultStrategiesExtension.cs


You need to comment out the following 4 lines:

Context.BuildPlanStrategies.AddNew(
UnityBuildStage.Initialization);

Context.BuildPlanStrategies.AddNew(
UnityBuildStage.Initialization);


Context.Policies.SetDefault(
new DefaultUnityPropertySelectorPolicy());

Context.Policies.SetDefault(
new DefaultUnityMethodSelectorPolicy());




Step 2: Recompile

0 comments:

Post a Comment

Post a comment