Base solution for your next web application
Open Closed

Accessing local changes within events #2163


User avatar
0
enigma created

Hey all,

We are running into an issue as our system becomes more complex. We have a number of aggregate roots that, upon change, require us to make various calculations within the system and save those to the database.

When an entity is updated, we need to pull in various other entities and perform calculations. If we try to use a repository in this event, it appears to query against the database instead of the local changes. This means that inserted entities are not found (which are required for our calculations).

On the other hand, if we try to use the updated (instead of ing) event, we cannot make any additional database changes because the context has been disposed.

Given that I assume events exist for this type of situation, I am wondering if we are doing something wrong or missing a key concept with how they should be used.

Any input is greatly appreciated! I am more than happy to add more clarification if necessary.

Thanks!


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

    Hi,

    For the current version of ABP, you need to use updated event and make your event unit of work. You can add UnitOfWork attribute to it's method.

    This is actuallay something we have to fix. We created an issue for this here <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1695">https://github.com/aspnetboilerplate/as ... ssues/1695</a>. After this is fixed and released you will be able to get changed entities in updating event in a single unit of work.

  • User Avatar
    0
    enigma created

    Thank you! I saw the changes are now available and look forward to trying them out.