Saturday, 15 June 2013

.net - Using Castle Dynamic Proxy with WebApi Contollers -


I am trying to use AOP logging using a castle's dynamic proxy library in a pure MVC 4 application. We are using the structure map for our dependency injection.

I have successfully installed AOP logging for our standard normal MVC controllers, but we also have a folder with webappi controllers that we use.

I have the problem that for any WEBApi call, I get the following error

  to type 'Castle.Proxies.IHttpControllerProxy' type of object Here is the set description of my interceptor set-up: Web, Controllers Services, Home, API Controller Name. "," Exception Type ":" System.Invalid Cost Option "  

Logging interceptor in / p>

  // strokecapemap objectfactory Start x Registry Interceptor (new logotype interceptor ());   

This is my process method

  public object process (object target, içitext reference) {var obj = new object (); Obj = _ProxyGenerator.CreateInterfaceProxyWithTargetInterface (target.GetType (). GetInterfaces (). First (), target.GetType (). GetInterfaces (), target, new logging interceptor ()); Return obj; }   

I suspect that I need to call a different method on _ProxyGenerator but I am new to making sure that I should call.

The problem is that your proxy class is simply copying the interface and not the base class, so When trying to insert internal webappi code of code, proxy to controller class if you call your call with CreateInterfaceProxyWithTargetInterface

  _proxyGenerator.CreateClassProxyWithTarget (target.GetType ( ), Target, change the new logging interceptor ();   

Then this problem will go away, but a new launch The proxy build will fail for any class which will not be a manufacturer with no error message, 'No parameterized constructor defined for this object.' Therefore you may have to add parameter constructor to all of your classes. You can switch to using Castle Windsor as your IOC.

No comments:

Post a Comment