Refactor DbContext and related interfaces to be generic#83
Merged
Conversation
- Made `BaseDbContext` and `IAuditContext` generic to support type parameter `T` for `AuditUser`. - Updated interceptors (`CreatableInterceptor`, `ModifiableInterceptor`, `SoftDeleteInterceptor`) to work with `IAuditContext<T>`. - Refactored `ICreatable`, `IModifiable`, `IDeletable`, `IEffectable`, and `IExpirable` interfaces to be generic. - Adjusted test classes and methods to align with the new generic structure. - Removed `SaveChanges_NoTagEntries` method; integrated its functionality into `SaveChanges`. - Modified `TestDbContext` and related tests to utilize the new generic interfaces.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the DbContext and related interfaces to be generic by introducing a type parameter T across audit, entity, interceptor, and testing components to improve type safety and flexibility.
- Updated interfaces (ICreatable, IModifiable, IDeletable, etc.) and the DbContext to include a generic type parameter T.
- Updated database interceptors and tests to use the generic implementations.
- Adjusted sample implementations to align with the new generic definitions.
Reviewed Changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/E13.Common.Data.Db.Tests/Sample/TestModifiable.cs | Updated to implement IModifiable. |
| test/E13.Common.Data.Db.Tests/Sample/TestInvalidDeletable.cs | Updated to implement IDeletable. |
| test/E13.Common.Data.Db.Tests/Sample/TestEffectable.cs | Updated to implement IEffectable. |
| test/E13.Common.Data.Db.Tests/Sample/TestDeletable.cs | Updated to implement IDeletable. |
| test/E13.Common.Data.Db.Tests/Sample/TestDbContext.cs | Changed to implement BaseDbContext and modified the SaveChanges call in AddTestData. |
| test/E13.Common.Data.Db.Tests/Sample/TestCreatable.cs | Updated to implement ICreatable. |
| test/E13.Common.Data.Db.Tests/BaseDbContext_*Tests.cs | Updated interceptors and assertions to use the generic versions. |
| src/E13.Common.Domain/* | Updated various entity interfaces to accept generic type parameter T with appropriate nullability. |
| src/E13.Common.Data.Db/Interceptors/* | Updated interceptors to work with the generic audit context and entity interfaces. |
| src/E13.Common.Data.Db/IAuditContext.cs | Modified interface to include generic type parameter T. |
| src/E13.Common.Data.Db/BaseDbContext.cs | Refactored to be generic (BaseDbContext) and updated property/setter definitions. |
Comments suppressed due to low confidence (1)
test/E13.Common.Data.Db.Tests/Sample/TestDbContext.cs:72
- Switching from SaveChanges_NoTagEntries() to SaveChanges() in AddTestData() may trigger additional tagging logic that was previously bypassed for arranging invalid data. Consider confirming if the new behavior is intended or if the test should still bypass those checks.
SaveChanges();
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a generic type parameter
Tacross multiple interfaces, classes, and interceptors in theE13.Commonlibrary to enhance type safety and flexibility. The changes primarily affect the audit context, entity interfaces, and database interceptors, requiring updates to dependent tests and sample implementations.Core Refactoring to Add Generic Type Parameter
T:Audit Context and BaseDbContext:
IAuditContextnow accepts a generic type parameterTforAuditUserto support non-string user identifiers. (src/E13.Common.Data.Db/IAuditContext.cs, src/E13.Common.Data.Db/IAuditContext.csL9-R11)BaseDbContextis updated toBaseDbContext<T>to align with the newIAuditContext<T>interface. (src/E13.Common.Data.Db/BaseDbContext.cs, [1] [2]Entity Interfaces:
ICreatable,IDeletable,IModifiable, and others now accept a generic type parameterTfor user-related fields (e.g.,CreatedBy,DeletedBy). (src/E13.Common.Domain/ICreatable.cs, [1];src/E13.Common.Domain/IDeletable.cs, [2]Interceptor Updates:
CreatableInterceptor,ModifiableInterceptor, andSoftDeleteInterceptorare updated to useIAuditContext<T>and the generic entity interfaces (e.g.,ICreatable<T>). (src/E13.Common.Data.Db/Interceptors/CreatableInterceptor.cs, [1];src/E13.Common.Data.Db/Interceptors/ModifiableInterceptor.cs, [2]Test Updates:
BaseDbContext<string>and generic interceptors. (test/E13.Common.Data.Db.Tests/BaseDbContext_ICreatableTests.cs, test/E13.Common.Data.Db.Tests/BaseDbContext_ICreatableTests.csL20-R30)BaseDbContext<string>.UnknownUserfor compatibility with the new generic implementation. (test/E13.Common.Data.Db.Tests/BaseDbContext_ICreatableTests.cs, test/E13.Common.Data.Db.Tests/BaseDbContext_ICreatableTests.csL59-R59)Sample Code Adjustments:
TestCreatableandTestDbContext, to use the generic interfaces andBaseDbContext<T>. (test/E13.Common.Data.Db.Tests/Sample/TestCreatable.cs, [1];test/E13.Common.Data.Db.Tests/Sample/TestDbContext.cs, [2]