Skip to content

[AMI-136] Improve EF Core integration and entity configuration - #11

Merged
hifeamin merged 5 commits into
mainfrom
feature/7-improve-ef-core-integration-and-entity
Nov 22, 2026
Merged

hifeamin merged 5 commits into
mainfrom
feature/7-improve-ef-core-integration-and-entity

Conversation

@hifeamin

Copy link
Copy Markdown
Collaborator

Implements AMI-136.

Summary

  • AddEfStores now accepts any DbContext; a startup validator fails fast with a clear message if the default Identity entities are not mapped.
  • New consolidated modelBuilder.AddRuntimeAppsAuthenticationEntities<TKey>(features => features.UseRefreshTokens().UseVerificationRequests()). Granular methods are unchanged and produce the same model.
  • Store transactions (TryRotateAsync, TryCreateAsync, TryResendAsync) run inside the DbContext execution strategy, so EnableRetryOnFailure providers work.
  • Rolled-back or failed entities are detached from the shared scoped context; TryResendAsync reads with AsNoTracking.
  • Verification send limits and supersede-pending are scoped per CustomPurpose / CustomChannel.
  • Samples use the consolidated extension; README gains an "EF Core integration" section (providers, limitations, FK guidance, migration impact).

Security considerations

  • No HTTP contract or status-code changes.
  • Rotation remains a conditional update, so a token can still be consumed only once. Custom purposes no longer share send limits or supersede each other.

Breaking changes / migration

  • Schema: two nullable nvarchar(128) columns (CustomPurpose, CustomChannel) on AuthenticationVerificationSends. Add a migration; existing rows stay NULL. Indexes unchanged.
  • The AddEfStores constraint is relaxed (source- and binary-compatible).

Testing

Not executed. Written in an environment without a .NET SDK, so neither the build nor the new SQLite tests (model, Identity round-trips, concurrent rotation, lockout, resend cooldown, custom purposes, retrying execution strategy) have been run. Opened as a draft until dotnet build and dotnet test pass locally.

Known limitations

  • Only SQLite is covered by tests; SQL Server/PostgreSQL are documented as expected to work.
  • Serializable-transaction aborts on those providers are not retried unless a retrying execution strategy is configured.
  • No foreign keys (documented, opt-in via user configuration); retention/purging deferred to AMI-139.

Generated by Claude Code

- AddEfStores accepts any DbContext and validates at startup that the
  default Identity entities are mapped
- Add AddRuntimeAppsAuthenticationEntities<TKey> consolidated model
  extension (granular methods unchanged)
- Run store transactions inside the DbContext execution strategy so
  retry-on-failure providers work
- Detach rolled-back/failed entities from the shared context; read the
  resend request with AsNoTracking
- Scope verification send limits and supersede to CustomPurpose and
  CustomChannel (adds two nullable columns to AuthenticationVerificationSends)
- Add SQLite model, Identity integration, concurrency and execution
  strategy tests; document providers, limitations and migration impact

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017CaSpYnH33eeK89z7wDB5X
IUserManager<TUser> does not expose role membership or password checks;
resolve Identity's UserManager<TUser> (same scoped instance) instead.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017CaSpYnH33eeK89z7wDB5X
HasConversion<string>() records the provider type without a ValueConverter
instance, so GetValueConverter() is null on the design-time model.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017CaSpYnH33eeK89z7wDB5X
…services

Other registrations (for example DataProtection) also add IHostedService.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017CaSpYnH33eeK89z7wDB5X
/// <c>AddRefreshTokenEntity</c> and <c>AddVerificationRequestEntity</c> methods remain available.
/// Table names or schemas can be overridden afterwards with standard EF Core fluent calls.
/// </summary>
public static ModelBuilder AddRuntimeAppsAuthenticationEntities<TKey>(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Remove this function.
Old AddRefereshTokenEntity and AddVerificationRequestEntity is ok.
There is no rule that one of them must be selected

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed AddRuntimeAppsAuthenticationEntities and its options class. Samples, tests and README now use the granular AddRefreshTokenEntity / AddVerificationRequestEntity methods only. Not compiled or run on my side yet.


Generated by Claude Code

Per review: AddRefreshTokenEntity and AddVerificationRequestEntity stay as
the only model configuration methods; no feature has to be selected.
Samples, tests and README go back to / use the granular methods.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017CaSpYnH33eeK89z7wDB5X
@hifeamin
hifeamin marked this pull request as ready for review November 22, 2026 20:29
@hifeamin
hifeamin merged commit 5d650c7 into main Nov 22, 2026
3 checks passed
@hifeamin
hifeamin deleted the feature/7-improve-ef-core-integration-and-entity branch November 22, 2026 20:41
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