-
Notifications
You must be signed in to change notification settings - Fork 0
Fix SDK version and Service Lifetimes #1
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
base: master
Are you sure you want to change the base?
Fix SDK version and Service Lifetimes #1
Conversation
- Update `global.json` to use installed .NET SDK 10.0.100. - Change `TranslationService`, `LyricsService`, `AudioSynthesisService`, and `DiagnosticService` lifetimes from Scoped to Singleton to enable proper caching and resource reuse. - Ensure validators are also Singleton to match the service lifetime. Co-authored-by: punkouter26 <[email protected]>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
| @@ -116,20 +116,20 @@ | |||
| builder.Services.Configure<ApiSettings>(builder.Configuration.GetSection("ApiSettings")); | |||
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.
The line builder.Services.Configure<ApiSettings>(builder.Configuration.GetSection("ApiSettings")); binds configuration to the ApiSettings class. If the ApiSettings section is missing or contains invalid values, this may result in runtime errors or misconfigured services. It is recommended to validate the configuration at startup and fail fast if required settings are missing or malformed. Consider adding explicit validation logic or using IOptions<ApiSettings> with validation:
builder.Services.AddOptions<ApiSettings>()
.Bind(builder.Configuration.GetSection("ApiSettings"))
.ValidateDataAnnotations()
.ValidateOnStart();This ensures configuration issues are detected early.
| builder.Services.AddSingleton<ITranslationService, TranslationService>(); | ||
| builder.Services.AddSingleton<ILyricsService, LyricsService>(); | ||
|
|
||
| // Register validation services | ||
| builder.Services.AddSingleton<ISpeechConfigValidator, SpeechConfigValidator>(); | ||
| builder.Services.AddScoped<IAudioSynthesisService, AudioSynthesisService>(); | ||
| builder.Services.AddSingleton<IAudioSynthesisService, AudioSynthesisService>(); | ||
| builder.Services.AddSingleton<IInputValidator, InputValidator>(); | ||
|
|
||
| // Register diagnostic validators | ||
| builder.Services.AddScoped<IDiagnosticValidator, AzureOpenAIDiagnosticValidator>(); | ||
| builder.Services.AddScoped<IDiagnosticValidator, AzureSpeechDiagnosticValidator>(); | ||
| builder.Services.AddScoped<IDiagnosticValidator, InternetConnectivityDiagnosticValidator>(); | ||
| builder.Services.AddScoped<IConfigurationValidator, ConfigurationValidator>(); | ||
| builder.Services.AddScoped<IDiagnosticService, DiagnosticService>(); | ||
| builder.Services.AddSingleton<IDiagnosticValidator, AzureOpenAIDiagnosticValidator>(); | ||
| builder.Services.AddSingleton<IDiagnosticValidator, AzureSpeechDiagnosticValidator>(); | ||
| builder.Services.AddSingleton<IDiagnosticValidator, InternetConnectivityDiagnosticValidator>(); | ||
| builder.Services.AddSingleton<IConfigurationValidator, ConfigurationValidator>(); | ||
| builder.Services.AddSingleton<IDiagnosticService, DiagnosticService>(); | ||
|
|
||
| // Register utility services | ||
| builder.Services.AddSingleton<ILyricsUtilityService, LyricsUtilityService>(); |
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.
All core, validation, diagnostic, and utility services are registered as singletons. If any of these services maintain state or depend on scoped services (such as HttpContext or per-request data), this can lead to data races or incorrect behavior. Review the implementation of these services to ensure singleton lifetime is appropriate. If any service requires per-request data, consider using AddScoped instead.
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
Updates the repository’s pinned .NET SDK version and adjusts DI registrations so core services can be reused/cached across requests instead of being re-instantiated per-scope.
Changes:
- Pin
global.jsonto .NET SDK10.0.100. - Change several server-side services (translation/lyrics/speech + diagnostics) from
ScopedtoSingletonlifetimes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/PoVicTranslate.Web/Program.cs |
Switches multiple service registrations to Singleton to enable cross-request caching/reuse. |
global.json |
Updates the pinned .NET SDK version used for builds. |
| // Register validation services | ||
| builder.Services.AddSingleton<ISpeechConfigValidator, SpeechConfigValidator>(); | ||
| builder.Services.AddScoped<IAudioSynthesisService, AudioSynthesisService>(); | ||
| builder.Services.AddSingleton<IAudioSynthesisService, AudioSynthesisService>(); |
Copilot
AI
Jan 28, 2026
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.
IAudioSynthesisService is now registered as a singleton, but AudioSynthesisService maintains mutable shared state (_accessToken / _tokenExpiry) without any synchronization. Under concurrent requests this can lead to races and redundant token fetches, and (in the worst case) using a stale token for a request. Consider adding an async lock/semaphore around token refresh (or using IMemoryCache with a single-flight pattern) so token acquisition is thread-safe when used as a singleton.
| builder.Services.AddSingleton<IAudioSynthesisService, AudioSynthesisService>(); | |
| builder.Services.AddScoped<IAudioSynthesisService, AudioSynthesisService>(); |
| builder.Services.AddScoped<ITranslationService, TranslationService>(); | ||
| builder.Services.AddScoped<ILyricsService, LyricsService>(); | ||
| builder.Services.AddSingleton<ITranslationService, TranslationService>(); | ||
| builder.Services.AddSingleton<ILyricsService, LyricsService>(); |
Copilot
AI
Jan 28, 2026
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.
With ILyricsService switched to singleton, LyricsService's SemaphoreSlim will live for the entire app lifetime. Since SemaphoreSlim is disposable and LyricsService doesn't implement IDisposable/IAsyncDisposable, consider disposing it (or refactoring to an alternative async-lock approach) to avoid holding undisposed resources for the process lifetime.
| builder.Services.AddSingleton<ILyricsService, LyricsService>(); | |
| builder.Services.AddScoped<ILyricsService, LyricsService>(); |
| "sdk": { | ||
| "version": "10.0.102", | ||
| "version": "10.0.100", | ||
| "rollForward": "latestPatch", | ||
| "allowPrerelease": false |
Copilot
AI
Jan 28, 2026
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.
global.json pins the SDK to 10.0.100 with rollForward: latestPatch. This setting will NOT roll forward to a different feature band (e.g., 10.0.102), so environments that only have newer 10.0.10x SDKs installed will fail with “SDK not found”. To keep builds resilient across dev/CI machines, consider using rollForward: latestFeature (or updating CI to install 10.0.100 specifically).
This PR addresses build issues by updating the
global.jsonto match the installed .NET SDK version. It also optimizes the application by changing several core services from Scoped to Singleton lifetime. This allowsLyricsServiceto cache lyrics data andAudioSynthesisServiceto cache Azure Speech tokens effectively, which was not working correctly with Scoped lifetime. It also prevents unnecessary instantiation ofAzureOpenAIClienton every request.PR created automatically by Jules for task 6263618300052399737 started by @punkouter26