Base solution for your next web application
Open Closed

Intercept AppService or DomainManager #4013


User avatar
0
bilalhaidar created

Hello In Abp, is there a standard way to intercept AppService or DomainManager so that I run some checking code before running the method?

The concept is similar to ASP. NET filters. I'm wondering if Abp offers a way to define such interceptors.

If not. An ASP. NET filter can be used for AppService methods?

Thanks


13 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi ,

    ABP does not offer anything for defining interceptors. You can use Castle Windsor's interceptors directly. You can check implementation of ValidationInterceptor, see <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Runtime/Validation/Interception/ValidationInterceptor.cs">https://github.com/aspnetboilerplate/as ... rceptor.cs</a>

    App services are considered as controllers in ASP.NET Core version, so for them, you can add your custom filters as well.

    Thanks.

  • User Avatar
    0
    bilalhaidar created

    Thanks Ismail. I will check the link.

    When you say, AppServices are considered as controllers in ASP.NET Core. What have been changed from ASP.NET MVC to ASP.NET Core to make AppServices as controllers? Isn't still the controllers dynamically generated in ASP.NET core?

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @bilalhaidar,

    ASP.NET Core allows us to use regular classses like controllers. ASP.NET MVC 5.x was not allowing that.

  • User Avatar
    0
    bilalhaidar created

    That's correct. Was that fact reflected in the way you generate the controllers? I assume you still generate controllers dynamically, right?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @bilalhaidar,

    No, actually we don't generate in ASP.NET Core, App services are used directly but of course there are some interceptions while using app services.

  • User Avatar
    0
    bilalhaidar created

    Thanks a lot. I will look into the ASPNET ZERO Core project to see what have been done.

    Thanks

  • User Avatar
    0
    bilalhaidar created

    Hello Ismail,

    I am trying to add a new Filter to the AppService assembly instead of using a Castle Windsor Interceptor.

    To create a new Controller's Filter, I must implement the interface (IAsyncActionFilter). This interface belongs to Microsoft.AspNetCore.Mvc.Abstractions.dll assembly.

    Shall I add a reference to that assembly into the AppService layer? My first thought would be against adding that, but what do you suggest?

    Shall I stick to an interceptor instead?

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Let's continue here <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/issues/549">https://github.com/aspnetzero/aspnet-ze ... issues/549</a> if it is the same case :)

  • User Avatar
    0
    bilalhaidar created

    Hi Ismail,

    Actually, I am asking here about MVC Filters and not Castle Windsor interceptors. You once mentioned I can add MVC Filters to AppServices since with ASP.NET Core AppServices are considered controllers.

    But then I noticed that I need to add some AspNet Core Dlls to the .Core project, so is that correct to do? Or better not to mix AspNet Core dlls inside .Core layer?

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Yes, it is better not to add ASP.NET Core dll's to your core project. Interception is a better choice for you I think.

  • User Avatar
    0
    bilalhaidar created

    Thanks. Can you please follow up on the GitHub issue I posted? You asked me if my AppService methods are designated with virtual or not. I really appreciate if you can have a look at it. Thank you

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @bilalhaidar,

    It seems like you have solved the problem.

  • User Avatar
    0
    bilalhaidar created

    I couldn't have solved it without your assistance.

    Thanks a lot