Using Unity in ASP.NET MVC to intercept controller method calls

Mar 26, 2009 at 12:17 AM
Hi everyone,

In your typical ASP.NET MVC application (NerdDinner 1.0 in particular) I have used the MvcContrib.Unity controller factory to resolve controllers and their dependencies. This all works. Next, I use the Interception extension to create transparent proxies for the controllers and their dependencies. When debugging I have verified that the proxies are indeed created. When I apply the LogCallHandler attribute, or set a (default) interceptor for the controllers and the dependencies, the call handler for the controller does not get called, but it does get called for the dependencies of the controller. If I make a call directly to the controller proxy I do see the LogCallHandler does its job. The actual call handler does not matter, because it happens for others as well. In a unit test for the controller, using the same Unity configuration and calling the action directly, everything works as intended. It's just when the action is invoked by the MVC runtime that this does not happen.

Just wondering what causes this. Stupidity on my part? Perhaps something in the way controller actions get invoked by the ControllerActionInvoker of MVC? Before I dive into this, perhaps someone has an answer ready.
I used the RTM version of ASP.NET MVC 1.0.

Mar 26, 2009 at 10:35 PM
It's probably in the ControllerActionInvoker. I haven't had a chance to dig into the details of that class yet.