You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem:
The current jasontaylordev/CleanArchitecture template uses hard deletes by default, permanently removing data from the database. In real-world enterprise applications, soft deletion is often a critical requirement for:
Auditability: Retaining data history for compliance and investigations.
Data Recovery: Allowing easy restoration of deleted records.
Non-Destructive Workflows: Supporting user deactivation, historical reporting, etc., without losing data.
Adding support for soft delete would align the template with robust data handling practices and long-term maintainability.
Proposed Solution:
To introduce soft delete functionality without compromising the template’s clean architecture:
Create ISoftDelete Interface
Define an interface with DateTime? Deleted and string? DeletedBy properties to mark entities as soft-deleted.
Update BaseAuditableEntity
Implement ISoftDelete in BaseAuditableEntity, or create a BaseSoftDeletableEntity if separation is preferred. This allows shared audit and delete functionality.
Apply Global Query Filters
In ApplicationDbContext, use EF Core’s global filters to automatically exclude soft-deleted entities (Deleted != null) from standard queries.
Override SaveChanges() for Soft Delete
Intercept EntityState.Deleted entities implementing ISoftDelete and convert them into Modified with deletion metadata set.
Add Hard Delete Option
Provide an opt-in method (e.g., HardDeleteAsync) for physical deletion when required.
Test Coverage
Add tests to verify:
Soft deletes mark the entity and exclude it from queries
Restoring or accessing deleted entities works via .IgnoreQueryFilters()
Unique constraints behave correctly with filtered indexes (if needed)
Uh oh!
There was an error while loading. Please reload this page.
Feature Proposal: Soft Delete Support
Problem:
The current
jasontaylordev/CleanArchitecture
template uses hard deletes by default, permanently removing data from the database. In real-world enterprise applications, soft deletion is often a critical requirement for:Adding support for soft delete would align the template with robust data handling practices and long-term maintainability.
Proposed Solution:
To introduce soft delete functionality without compromising the template’s clean architecture:
Create
ISoftDelete
InterfaceDefine an interface with
DateTime? Deleted
andstring? DeletedBy
properties to mark entities as soft-deleted.Update
BaseAuditableEntity
Implement
ISoftDelete
inBaseAuditableEntity
, or create aBaseSoftDeletableEntity
if separation is preferred. This allows shared audit and delete functionality.Apply Global Query Filters
In
ApplicationDbContext
, use EF Core’s global filters to automatically exclude soft-deleted entities (Deleted != null
) from standard queries.Override
SaveChanges()
for Soft DeleteIntercept
EntityState.Deleted
entities implementingISoftDelete
and convert them intoModified
with deletion metadata set.Add Hard Delete Option
Provide an opt-in method (e.g.,
HardDeleteAsync
) for physical deletion when required.Test Coverage
Add tests to verify:
.IgnoreQueryFilters()
Impact Areas:
Domain.Common/ISoftDelete.cs
(new)Domain.Common/BaseAuditableEntity.cs
(modified)Infrastructure/Data/ApplicationDbContext.cs
Application/TodoLists/Commands/DeleteTodoList/
(usage example)This feature will enhance the CleanArchitecture template’s production readiness and align it with common enterprise data practices.
I’m currently implementing this feature and will submit a pull request shortly.
The text was updated successfully, but these errors were encountered: