Base solution for your next web application
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?

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

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?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • 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

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • 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.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)