Base solution for your next web application
Open Closed

Get unproxied target object from castle.dynamic.{Class}Proxy #4771


User avatar
0
artj created

Hi,

We are trying to inherit the following class, because we need to define a different behavior based on business rules:

LogInManager : AbpLogInManager<Tenant, Role, User>, ILogInManager
{
...
}

Inherit like:

LogInManagerLocal : LogInManager
{
...
}

When we try to parse these classes on the method WinAuthenticate on {projectName}\src\weber.{ProjectName}.web.core\controllers\tokenauthcontroller.cs

[Route("api/[controller]/[action]")]
public class TokenAuthController : VFAOControllerBase
{
   TokenAuthController(LogInManager logInManager,...){}

   ...
   
   public async Task<AuthenticateResultModel> WinAuthenticate([FromBody] AuthenticateModel model)
   {
      var childObj = logInManager as LogInManagerLocal
   ....
   }
}

The variable childObj is null, because the variable is proxied by the time it gets into the method, so instead of being of type LogInManager, is Castle.Dynamic.LogInManagerProxy. Is there a well-design approach that allow us to get the base clase, in this case would be from LogInManager type?

Thanks.


3 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    see

    • <a class="postlink" href="https://stackoverflow.com/questions/11082911/castle-dynamicproxy-get-unproxied-object">https://stackoverflow.com/questions/110 ... ied-object</a>
    • <a class="postlink" href="https://stackoverflow.com/questions/26442864/castle-dynamic-proxy-object-to-original-object-convertion">https://stackoverflow.com/questions/264 ... convertion</a>
  • User Avatar
    0
    artj created

    What was commented on the links didn't work for me, because they are trying to do what castle.core.dynamic is trying to do behind the scene.

    For instance, if I call ProxyUtil.GetUnproxiedType() (<a class="postlink" href="https://github.com/castleproject/Core/blob/master/src/Castle.Core/DynamicProxy/ProxyUtil.cs#L66">https://github.com/castleproject/Core/b ... til.cs#L66</a>) it returns {CompName}.{projName}.Authorization.LogInManager, and that's correct; but it gets it wrong when call ProxyUtil.GetUnproxiedInstance(), because it keeps returning the proxied class Castle.Proxies.LogInManagerProxy as it were the target.

    Is there any other approach? Also, What kind of target is AspnetZero is using <a class="postlink" href="https://github.com/castleproject/Core/blob/master/docs/dynamicproxy-kinds-of-proxy-objects.md">https://github.com/castleproject/Core/b ... objects.md</a> ? Last, Where the parameters for the controller are being passed?

    Thanks for your time!

  • User Avatar
    0
    aaron created
    Support Team

    This is not a proxy problem. Inject LogInManagerLocal:

    public class TokenAuthController : VFAOControllerBase
    {
       TokenAuthController(LogInManagerLocal logInManager, ...) { }
    
       // ...
    }