Performance issues using Unity Interception

Oct 22, 2010 at 11:02 AM

 Hi Our MVC application uses Unity 1.2 for Dependency Injection. Currently we are performing some load testing and found out every time when we hit certain number of users (i.e 40) the app gets really slow and the processor’s memory usage get maxed out. We spent a week trying to identify the problem and finally we narrowed down to the code that causes the problem.

Line 1 - unityContainer.Parent.AddNewExtension();

Line 2 - unityContainer.Parent.Configure().SetDefaultInterceptorFor(new InterfaceInterceptor ());

Line 3 - unityContainer.Parent.RegisterType();

Once I remove Line 1 and Line 2 our app performs well and no issues in load testing. We use the default interceptor for ICustomerServiceProxy as the implementation of ICustomerServiceProxy has a method which decorated with a AppCache attribute. For example

public class CustomerServiceProxy: ICustomerServiceProxy


[AppCache(Scope.Application, Expiration = "never")]

public IEnumerable GetAllCustomers(bool forceUpdate)


The AppCache attribute is custom attribute and the imeplementation is....

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)]

public class AppCacheAttribute : HandlerAttribute



public override ICallHandler CreateHandler(IUnityContainer ignored)


         return new AppCachingCallHandler(GetCacheScope(_cacheScope), Order);


public class AppCachingCallHandler : ICallHandler


         public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)

       { //...



Any ideas greatly appreciated. Please let me know if you need more information.

Cheers, Raj

Oct 27, 2010 at 1:12 PM

It sounds like you're creating a new instance of Unity for each user/request.  Is that right?