Base solution for your next web application
Open Closed

Calling Application Service from BackgroundJobs #1292


User avatar
0
andis created

We are planning to create an import module. Actually by import module is nothing more than just an action to let user trigger Application Service Action repeatly with different input. Our design is to let users upload an excel, define the application service and its method they want invoke.. After that, background job can impersonate that user to do the input(all validations, audit logs and permissions are based on the uploading users). Is there anyway to achieve this?


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

    While we haven't tried such a service, it should be possible. You will need to implement IAbpSession for that, since authorization gets userid/tenantid from AbpSession. After implementing your solution, share here so we can review it.

  • User Avatar
    0
    andis created

    How aspnetboilerplate create Proxied Application Service? I need to create it in the same way so they can have similar behaviour

  • User Avatar
    0
    hikalkan created
    Support Team

    What do you mean by "Proxied Application Service"? You mean "Castlw dynamic proxy"? If so, it's automatically done when you use dependency injection and inject app service by it's interface.

    But.. as I see your case is a bit different. Creating a new session implementation is not possible, because it will also replace the session in web application since your background job is working in the same process.

    Current session gets userId and tenantId from cookies. You, somehow, should change it to be manually changable for an async flow. You can try AsyncLocal for that.. but this may be a bit complicated and requires some multithreading knowledge. But I could not find another way yet.

  • User Avatar
    0
    andis created

    Yes, I mean Castle Dynamic Proxy, can you give me aspboilerplate code where setting these service up? I am trying to understand it more

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    I created a sample code but not tried it: <a class="postlink" href="https://gist.github.com/hikalkan/943a0eae1d9d5994c833daed81c463e9">https://gist.github.com/hikalkan/943a0e ... ed81c463e9</a>

  • User Avatar
    0
    andis created

    Hi,

    Thanks for creating sample code for me..

    Can I know, how aspnetboilerplate setting up my application service? include their interceptor, I wonder if I can find these code in this solution? <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate">https://github.com/aspnetboilerplate/aspnetboilerplate</a>

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    There are a few interceptors for App services:

    • Authorization: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Authorization/Interceptors/AuthorizationInterceptorRegistrar.cs#L20">https://github.com/aspnetboilerplate/as ... rar.cs#L20</a>
    • Validation: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Runtime/Validation/Interception/ValidationInterceptorRegistrar.cs#L17">https://github.com/aspnetboilerplate/as ... rar.cs#L17</a>
    • UOW: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Domain/Uow/UnitOfWorkRegistrar.cs#L25">https://github.com/aspnetboilerplate/as ... rar.cs#L25</a> (IsConventionalUowClass: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Domain/Uow/UnitOfWorkHelper.cs#L19">https://github.com/aspnetboilerplate/as ... per.cs#L19</a>)