Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Calling The Interceptor #3087


User avatar
0
amrsaafan created

Hello,

How to call the interceptor which is created in application service layer from Web MVC Controller?


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

    Hi,

    Normally, interceptors (unit of work, authorization, validation) automatically work when you call an application service method and you shouldn't need to use them directly. Can you write your purpose and use case for a better help?

  • User Avatar
    0
    jefftindall created

    Halil,

    In context, there is an interceptor to apply parameters to a data filter based on the user context. Everything in the WebAPI works well, but file download via WebAPI is not really great, so we created an MVC action. In order to ensure/enforce proper security, the data filters must be set. We could certainly apply them manually in the controller action, but the thought was to get part of the record through the AppService pipeline in hopes it would be automatic.

    public ActionResult Download(int recordId)
    {
      var record = _appService.Get({id = recordId}); // Interceptor is not hit
      var pdf = renderPdf(record);
      return File(pdf);
    }
    

    I tried to look through the code to see how the interceptor is executed, but I did not find anything obvious. I presume it is registered somewhere in the IocManager, but never found it.

    Thanks, Jeff

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Are you sure that you have injected your application service via it's interface (not concrete class)? If it's required to inject by class, then you need to make your app service method virtual, otherwise dynamic proxy can not work.