Skip to content

feat: implement IUserRegistrationManager interface and refactor RegisterAsync on UserRegistrationManager#4837

Open
ntuthukomsane-boxfusion wants to merge 2 commits intoshesha-io:releases/0.43from
ntuthukomsane-boxfusion:ntuthuko/enhancement/override-register-async
Open

feat: implement IUserRegistrationManager interface and refactor RegisterAsync on UserRegistrationManager#4837
ntuthukomsane-boxfusion wants to merge 2 commits intoshesha-io:releases/0.43from
ntuthukomsane-boxfusion:ntuthuko/enhancement/override-register-async

Conversation

@ntuthukomsane-boxfusion
Copy link
Copy Markdown

@ntuthukomsane-boxfusion ntuthukomsane-boxfusion commented Apr 20, 2026

#4828

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced reliability of external user registration by implementing transaction scoping to ensure data consistency during the login registration process.
  • Refactor

    • Improved code architecture by introducing an abstraction layer for user registration functionality, enabling better modularity and testability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 20, 2026

Warning

Rate limit exceeded

@ntuthukomsane-boxfusion has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 44 minutes and 40 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 44 minutes and 40 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e03b7abc-5f8a-4831-89b9-5bc8371cc5a7

📥 Commits

Reviewing files that changed from the base of the PR and between acaf92b and f271d55.

📒 Files selected for processing (1)
  • shesha-core/src/Shesha.Application/Authorization/TokenAuthController.cs

Walkthrough

This PR introduces an IUserRegistrationManager interface for user registration, updates UserRegistrationManager to implement it with a virtual RegisterAsync method, registers the interface in dependency injection, and modifies TokenAuthController to use the interface while improving external user login persistence with transactional safety.

Changes

Cohort / File(s) Summary
User Registration Interface & Implementation
shesha-core/src/Shesha.Framework/Authorization/Users/IUserRegistrationManager.cs, shesha-core/src/Shesha.Framework/Authorization/Users/UserRegistrationManager.cs
Introduced IUserRegistrationManager interface with RegisterAsync method contract. Updated UserRegistrationManager to implement the interface, removed IPasswordHasher<User> dependency, and made RegisterAsync virtual to enable overrides.
Dependency Injection Configuration
shesha-core/src/Shesha.Framework/SheshaFrameworkModule.cs
Added DI registration binding IUserRegistrationManager to UserRegistrationManager with Transient lifestyle.
Token Authentication Controller
shesha-core/src/Shesha.Application/Authorization/TokenAuthController.cs
Updated to inject IUserRegistrationManager interface instead of concrete implementation. Modified RegisterExternalUserAsync to wrap login persistence in a new transaction scope, load persisted user from repository, and add UserLogin entry within transaction context before returning persisted user.

Sequence Diagram

sequenceDiagram
    actor Client
    participant TokenAuthController
    participant IUserRegistrationManager
    participant IRepository
    participant UnitOfWork
    participant Database

    Client->>TokenAuthController: POST external user registration
    TokenAuthController->>IUserRegistrationManager: RegisterAsync(user details)
    IUserRegistrationManager->>Database: Create new user
    IUserRegistrationManager->>UnitOfWork: SaveChangesAsync()
    IUserRegistrationManager-->>TokenAuthController: Return registered user
    
    TokenAuthController->>UnitOfWork: Create new transaction scope (RequiresNew)
    TokenAuthController->>IRepository: GetAsync(user.Id)
    IRepository->>Database: Load persisted user
    Database-->>IRepository: Return user
    IRepository-->>TokenAuthController: Return persisted user
    
    TokenAuthController->>TokenAuthController: Add UserLogin to persistedUser.Logins
    TokenAuthController->>UnitOfWork: CompleteAsync()
    UnitOfWork->>Database: Commit UserLogin changes
    TokenAuthController-->>Client: Return persisted user with login
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐰 A registration interface appears,
With transactions to calm our fears,
Virtual methods for override cheer,
Dependencies swapped without tear,
External logins now persist clear! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately and specifically describes the main changes: introducing the IUserRegistrationManager interface and refactoring RegisterAsync on UserRegistrationManager, which are the primary objectives reflected in all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@shesha-core/src/Shesha.Application/Authorization/TokenAuthController.cs`:
- Around line 338-353: The code opens a new transaction with
UnitOfWorkManager.Begin(TransactionScopeOption.RequiresNew) and then calls
_userRepository.GetAsync(user.Id), which can fail because the newly created user
from RegisterAsync is not yet committed; instead perform the user creation and
login addition in the same unit of work: either remove the RequiresNew Begin
call and use the ambient/current UOW (so directly add the new UserLogin to
persistedUser.Logins before completing the existing UOW) or move the
RegisterAsync call into a single explicit UOW scope so that RegisterAsync and
the UserLogin addition occur within the same UnitOfWork; update the code around
UnitOfWorkManager.Begin, RegisterAsync, and persistedUser.Logins.Add to ensure
atomicity.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 128e3279-0d53-4152-8d5f-bcf15deb402b

📥 Commits

Reviewing files that changed from the base of the PR and between 235b3f9 and acaf92b.

📒 Files selected for processing (4)
  • shesha-core/src/Shesha.Application/Authorization/TokenAuthController.cs
  • shesha-core/src/Shesha.Framework/Authorization/Users/IUserRegistrationManager.cs
  • shesha-core/src/Shesha.Framework/Authorization/Users/UserRegistrationManager.cs
  • shesha-core/src/Shesha.Framework/SheshaFrameworkModule.cs

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.

3 participants