-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce RepositoryInterceptor
and Enable/DisableTracking()
extension methods.
#17491
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #17491 +/- ##
==========================================
- Coverage 53.60% 53.55% -0.05%
==========================================
Files 3025 3032 +7
Lines 94418 94604 +186
==========================================
+ Hits 50610 50664 +54
- Misses 43808 43940 +132
... and 4 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
RepositoryInterceptor
and IRepository.DisableTracking()
extension methods. RepositoryInterceptor
and Enable/DisableTracking()
extension methods.
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryHelper.cs
Outdated
Show resolved
Hide resolved
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryInterceptor.cs
Outdated
Show resolved
Hide resolved
@@ -107,7 +108,7 @@ public EfCoreRepository(IDbContextProvider<TDbContext> dbContextProvider) | |||
|
|||
public async override Task<TEntity> InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) | |||
{ | |||
CheckReadOnly(); | |||
CheckChangeTracking(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inserting/updating/deleting an entity work even if you don't track changes for queried entities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the entity returned by the method or entity from parameters is no tracking
after the method is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where it is done? I didn't see any code part that detaches inserted/updated entities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be code like this, So I think output warning logs are necessary.
using (var uow = uowManager.Begin())
{
var author = await authorRepository.InsertAsync(new Author(Guid.NewGuid(), "Douglas"));
// Entity still under tracking
author.Name = "Douglas2";
await uow.CompleteAsync();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, in this example, author
object is being tracked, and the name change is auto-saved, right? But the warning message says "Your changes may not be saved". Isn't that misleading the developer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code I share will not work if we disable entity tracking.
But developers may use such code, so I think we should output warnings when entity tracking is disabled.
Added two extension methods so the developer can disable/enable entity tracking by these methods manually.
The
EnableEntityChangeTrackingAttribute
andDisableEntityChangeTrackingAttribute
can be used by class/interface/method. TheRepositoryInterceptor
will get itsEnabled
property and change the currentTracking
value byIEntityChangeTrackingProvider
.The
Repository
will check these conditions to decide whether to enable tracking.IsChangeTrackingEnabled
(null
by default. You can change it byDisableTracking
orEnableTracking
)Tracking
value ofIEntityChangeTrackingProvider
. (It will benull
if there is noEntityChangeTrackingAttribute
)true
by default.Resolves #17487
Checklist