views:

307

answers:

2

I'm running into an issue with the Policy Injection Application Block from Enterprise Library in conjunction with ASP.NET MVC.

In my ControllerFactory, I'm creating the controller and then calling PolicyInjection.Wrap on the controller. This gives me back a Transparent Proxy to the controller which manages the call handler chain.

Finally, I cast the Transparent Proxy to an IController and return it.

This seems to work well, except that none of the call handlers I've defined for my controller are executing. (For example I have a Logging Handler configured, but nothing is being logged by PIAB.)

Is my final cast messing this up somehow? How does ControllerBase.Execute() call into my controller? It seems like my proxy should be utilized. Anyone using PIAB on ASP.NET controllers?

A: 

Seems at least one person uses it :) - ASP.NET MVC Validation using Policy Injection Application Block in Enterprise Library (this is first result BTW)

Mike Chaliy
Thanks Mike. I've read this before but this is about using PIAB with MODELS, not controllers.
nikmd23
Yep, my fault..
Mike Chaliy
+1  A: 

I am using PIAB to wrap ASP.NET MVC Controllers, and I'm doing so by calling

PolicyInjection.Wrap<IController>(instance)

which will wrap the IController methods. I'm also using policy injection to wrap the IActionInvoker that gets used as well, which allows for logging the action name.

I have not had success wrapping controllers using the MarshalByRefObject wrapping, but the interface wrapping works like a charm.

If you want additional information, you could create an interface that has all the methods from IController, IActionFilter, IAuthorizationFilter, IExceptionFilter and IResultFilter and then have your controllers implement that interface. Then you could wrap your controllers as that interface and get more calls going through policy injection.

I hope that helps. If you have more specific issues please post.

John Bledsoe
In MVC 2, Controller no longer subclasses MarshalByRefObject because it never worked with PIAB. Essentially, the controller's actual *this* reference gets passed around instead of the proxy reference for the purpose of invocation, which causes the PIAB mechanisms to be bypassed.Using interfaces as suggested in this answer should continue to work just fine.
Levi