1

I'm using Autofac with DynamicProxy2 to intercept my classes like this

builder.RegisterType<Calculator>().As<ICalculator>().EnableInterfaceInterceptors()
                .InterceptedBy(typeof (CallLogger));

This will intercept all methods on given interface.

Is there any way to intercept only particular methods of the interface ?

4

1 回答 1

2

There are a couple of ways I can think of, and there are probably more out there.

You could create a custom attribute like [LogCall] or [DoNotLogCall] (opt in or opt out) and apply that to the methods to intercept, then check for the presence of the attribute inside CallLogger.

Or, you could configure the CallLogger with the names of (or rules to find) the methods that should be logged.

于 2011-01-28T00:29:17.073 回答