Description
Description
Feature Request: Add methods in DefaultResourceRepository so that derived classes have access to the DBContext and an opportunity to intercept calls to _context.SaveChangesAsync() in CreateAsync, UpdateAsync, UpdateRelationshipsAsync, DeleteAsync.
Use Case: I have a fairly complex order-entry model. Any time any part of the hierarchy is modified I need to load the aggregate root and the subtotals for the entire hierarchy. Simply inheriting DefaultResourceRepository and overriding the relevant methods presents the following problems:
The derived class doesnt have direct access to the DBContext
Putting my recalculation call before the call to the base class means the entity instance will not have its relationships loaded which is required in this case to perform the calculation
Putting my recalculation call after the call the the base class would result in multiple calls to _dbContext.SaveChangesAsync() and thus multiple database transactions.
This can easily be solved with a minimum of architectural change by simply exposing a couple of well placed protected virtual methods on DefaultRespository<TResource,TId>. This way the default EFCore abstraction is maintained except for classes which explicitly inherit and override those methods. This way the changes are isolated to the places in the code which are already dependent on EFCore and don't affect the larger api surface.
Implementing this without the proposed virtual methods involved copy-pasta of the entire DefaultRepository class as well as a large chunk of internal reflection code.
Use Case
I am working on a point-of-sale system where any time any part of the tab is modified, the entire tab needs its subtotal and tax recalculated.
...
Environment
- JsonApiDotNetCore Version:
- Other Relevant Package Versions: