-
-
Notifications
You must be signed in to change notification settings - Fork 10
Fix StatisticsService dependency injection lifetime mismatch #4089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughThe dependency injection container configuration is modified to register StatisticsService with Scoped lifetime instead of Singleton. This ensures a new instance is created per request scope rather than reused globally throughout the application. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)Backend/Startup.cs (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
🔇 Additional comments (1)
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. Comment |
Co-authored-by: imnasnainaec <6411521+imnasnainaec@users.noreply.github.com>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this 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 fixes a dependency injection lifetime mismatch where StatisticsService was registered as a Singleton while depending on Transient-scoped repositories. This caused the service to capture and retain the first repository instances indefinitely, leading to potential issues with stale database connections and incorrect data isolation between requests.
Key Changes:
- Changed StatisticsService registration from
AddSingletontoAddScopedin the DI container
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4089 +/- ##
===========================================
+ Coverage 74.57% 85.59% +11.02%
===========================================
Files 295 54 -241
Lines 10938 4777 -6161
Branches 1372 589 -783
===========================================
- Hits 8157 4089 -4068
+ Misses 2385 544 -1841
+ Partials 396 144 -252
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
imnasnainaec
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@imnasnainaec reviewed all commit messages and made 1 comment.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion.
Backend/Startup.cs line 277 at r1 (raw file):
// Statistics types services.AddScoped<IStatisticsService, StatisticsService>();
Updated issue: this should be AddTransient instead of AddScoped.
|
Replaced by #4093 |
StatisticsService was registered as Singleton while depending on Transient-scoped repositories (IWordRepository, IUserRepository), causing the service to capture and retain the first instances indefinitely instead of getting fresh instances per scope.
Changes
AddSingletontoAddScopedinBackend/Startup.csScoped lifetime aligns with ASP.NET Core conventions for services with database dependencies and ensures proper disposal within HTTP request boundaries.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
This change is
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.