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

UnitOfWork - Separate transactions in one UOW method #2331


User avatar
0
chrisk created

Hi,

I'm trying to execute some code as separate transaction inside UoW method. Basically I got IApplicationService which receives some order data and then selects appropriate workflow to execute. Workflows are created in a way so those can be easily turned into background job. but at the moment I'm executing them within my AppService method so there is already UoW applied right?

What I need to do now is to capture errors that are occurring and send email notification. I implemented email notifications using AbpNotifications. My problem is that I want to rollback all changes that were generated within workflow execution then publish notification and rethrow any errors from my workflow so those will be logged and displayed on UI.

Than you very much


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

    Hi,

    What about Exception Event <a class="postlink" href="http://aspnetboilerplate.com/Pages/Documents/Handling-Exceptions#DocExceptionEvent">http://aspnetboilerplate.com/Pages/Docu ... ptionEvent</a> ? If you use it, you can send email notifications in this event and everyting else will work as you want.

  • User Avatar
    0
    chrisk created

    Hi,

    Thank you very much for response. I was considering solution that you proposed and but I'm not sure how I could get detailed information using this approach. I need to get bit more detailed information about errors occurring in my workflows as well as possibility to execute within IApplicationService or as BackgroundJob.

    In the end I got it to work in following way :

    • Changed implementation of workflows to handle exceptions internally (previously workflow could throw exceptions and were handled in my IApplicationService but I had to made it possible to execute the same workflow as background job)

    • Changed return type of my "Execute(input)" public method of workflow from void to WorkflowExecutionResult (WorkflowExecutionResult is used to return whether execution was successful or not and errors are passed as list of ValidationResult so I can use those to throw AbpValidationException in my IApplicationService if I want to display errors to client)

    • Last thing was making Workflow.Execute method to execute as Separate UoW transaction, I used - [UnitOfWork(TransactionScopeOption.RequiresNew)]. Originally that caused me problems and was the reason to start this post. I think what I was doing wrong was that my workflow classes are not implementing shared interface thus are not called over interface and with old signature which was public void Execute() method wasn't intercepted. Changing signature to virtual did the job.

    Does it sound like valid solution? I hope I'm not missing something and wont try to fight against framework.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Sorry for my late response. Your solution seems fine.

    You are executing a workflow and ABP does not have any build in staff for workflows. I think, your solution is good :).

  • User Avatar
    0
    chrisk created

    Hi,

    Thank you very much for response it means a lot to me especially because when I started working with Abp my developing skills improved same as quality of my work and timings - it was most complex and at the same time very well structured - simply best working project I worked with so far. For me as for junior developer Abp is an example of top quality software which I want to follow and your github repo serves for me as a holly book- I love the patterns and techniques used :)

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    It is really nice to hear such nice comments :). We are trying to keep this work as good as we can.