Fix static field mutation in CrystaProgramSyncModuleService constructor#115
Merged
afshinalizadeh merged 6 commits intofeature/afshin/add-sync-githubfrom Jan 8, 2026
Merged
Conversation
- Removed static keyword from _modules field to prevent shared state issues - Changed from AppDbContext to IDbContextFactory<AppDbContext> for proper singleton support - Added lazy initialization with thread-safe semaphore lock - Changed service registration from Transient to Singleton - Updated Fake service with same pattern for consistency Co-authored-by: afshinalizadeh <4254006+afshinalizadeh@users.noreply.github.com>
- Add Microsoft.EntityFrameworkCore using statement for EF Core extensions - Add thread-safe synchronization for UpdateSyncModuleAsync with SemaphoreSlim - Move initialization to async method with proper thread-safety in Fake service - Add synchronization locks for in-memory list modifications Co-authored-by: afshinalizadeh <4254006+afshinalizadeh@users.noreply.github.com>
- Add CancellationToken parameter to interface method with default value - Propagate cancellation token through all database operations - Pass cancellation token to AddAsync and SaveChangesAsync methods Co-authored-by: afshinalizadeh <4254006+afshinalizadeh@users.noreply.github.com>
- Add IDisposable implementation to both service classes - Properly dispose SemaphoreSlim instances to free unmanaged resources - Add _disposed flag to prevent double disposal Co-authored-by: afshinalizadeh <4254006+afshinalizadeh@users.noreply.github.com>
- Pass cancellation token to semaphore wait operations - Enable proper cancellation propagation during initialization Co-authored-by: afshinalizadeh <4254006+afshinalizadeh@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update sync GitHub feature implementation based on feedback
Fix static field mutation in CrystaProgramSyncModuleService constructor
Dec 26, 2025
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.
The service constructor was writing to a static field, causing thread-safety issues and defeating transient DI registration. Multiple service instances shared the same static
_moduleslist, leading to race conditions.Changes:
AppDbContextinjection toIDbContextFactory<AppDbContext>, enabling singleton lifetime with scoped DbContext creation_modulesinstance-based with thread-safe lazy initialization usingSemaphoreSlimIDisposableto cleanup semaphore resourcesCancellationTokenparameter toUpdateSyncModuleAsyncinterface and propagated through all async operationsBefore:
After:
Applied same pattern to
CrystaProgramSyncModuleServiceFake.💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.