Skip to content

Refactor DbContext and related interfaces to be generic#83

Merged
JJBussert merged 2 commits into
e13tech:mainfrom
JJBussert:main
Apr 24, 2025
Merged

Refactor DbContext and related interfaces to be generic#83
JJBussert merged 2 commits into
e13tech:mainfrom
JJBussert:main

Conversation

@JJBussert
Copy link
Copy Markdown
Contributor

This pull request introduces a generic type parameter T across multiple interfaces, classes, and interceptors in the E13.Common library 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:

    • IAuditContext now accepts a generic type parameter T for AuditUser to support non-string user identifiers. (src/E13.Common.Data.Db/IAuditContext.cs, src/E13.Common.Data.Db/IAuditContext.csL9-R11)
    • BaseDbContext is updated to BaseDbContext<T> to align with the new IAuditContext<T> interface. (src/E13.Common.Data.Db/BaseDbContext.cs, [1] [2]
  • Entity Interfaces:

    • Interfaces like ICreatable, IDeletable, IModifiable, and others now accept a generic type parameter T for user-related fields (e.g., CreatedBy, DeletedBy). (src/E13.Common.Domain/ICreatable.cs, [1]; src/E13.Common.Domain/IDeletable.cs, [2]

Interceptor Updates:

  • Database Interceptors:
    • CreatableInterceptor, ModifiableInterceptor, and SoftDeleteInterceptor are updated to use IAuditContext<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:

Sample Code Adjustments:

  • Sample Entities and Context:
    • Updated sample implementations, such as TestCreatable and TestDbContext, to use the generic interfaces and BaseDbContext<T>. (test/E13.Common.Data.Db.Tests/Sample/TestCreatable.cs, [1]; test/E13.Common.Data.Db.Tests/Sample/TestDbContext.cs, [2]

JJBussert and others added 2 commits April 24, 2025 11:21
- 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.
@JJBussert JJBussert requested a review from Copilot April 24, 2025 16:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

@JJBussert JJBussert merged commit 29f5b42 into e13tech:main Apr 24, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants