Is there any way to disable Method and Property injection and Interception features?

May 18, 2012 at 10:47 AM

Is there any way to disable Method and Property injection and Interception features? I want to measure if it influence speed of object graph creation.

May 24, 2012 at 3:39 AM

Unity Interception is implemented as a UnityContainerExtension and it is not added by default (all of the logic is in a separate assembly).

I'm not sure if you can 100% remove method and property injection (I wasn't able to do it but perhaps someone else has?).  I was able to swap out the default implementation with another so that the overhead would be minimal:

    class Program
    {
        static void Main(string[] args)
        {
            UnityContainer container = new UnityContainer();
            container.AddNewExtension<RemoveContainerExtension>();

            var x = container.Resolve<MyClass>();
        }
    }

    public class RemoveContainerExtension : UnityContainerExtension
    {
        protected override void Initialize()
        {
            Context.Policies.SetDefault<IPropertySelectorPolicy>(new MyPropertySelector());
            Context.Policies.SetDefault<IMethodSelectorPolicy>(new MyMethodSelector());
        }

        public class MyMethodSelector : IMethodSelectorPolicy
        {
            public IEnumerable<SelectedMethod> SelectMethods(IBuilderContext context, IPolicyList resolverPolicyDestination)
            {
                return Enumerable.Empty<SelectedMethod>();
            }
        }

        public class MyPropertySelector : IPropertySelectorPolicy
        {
            public IEnumerable<SelectedProperty> SelectProperties(IBuilderContext context, IPolicyList resolverPolicyDestination)
            {
                return Enumerable.Empty<SelectedProperty>();
            }
        }
    }

Another approach would be to download and modify the source code to do exactly what you want.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Jun 12, 2012 at 2:42 PM
Edited Jun 12, 2012 at 2:43 PM

Thanks. I will try on our project and see what results regarding application start up time are.

Jul 11, 2012 at 3:21 PM

Hi,

related to the previous question.  In my project we are using the unity interception but in one of the scenario i don't want to execute the interception call.  That means based on the config switch i want to disable the specific interception call.

HandlerAttribute has the createhandler method with return type of iCallHandler.  is there any way that i can return a dummy call hander when my switch says off the callhandler.

 

 

Jul 12, 2012 at 7:05 AM

I would recommend starting a new discussion with your specific scenario.  You can use matching rules in configuration to enable/disable interception.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com