This pull request refactors how session authentication is handled based on configuration, simplifying dependency injection and removing nullable checks for the session service. The session service is now always registered, but only provides functionality if authentication is required, improving code clarity and maintainability. The most significant changes are grouped below.
Dependency Injection and Service Registration:
- Replaced conditional registration of
ISessionServiceinProgram.cswith unconditional registration of a newConditionalSessionServicethat internally checks configuration to determine if session functionality should be enabled. (listenarr.api/Program.cs, listenarr.api/Program.csL98-R99) - Introduced
ConditionalSessionService, a wrapper that delegates toSessionServiceonly when authentication is enabled, throwing exceptions or returning defaults otherwise. (listenarr.api/Services/ConditionalSessionService.cs, listenarr.api/Services/ConditionalSessionService.csR1-R89)
Controller and Middleware Refactoring:
- Removed nullable checks for
ISessionServiceinAccountControllerand updated constructor and usages to always expect a non-null session service, handling disabled authentication via exceptions. (listenarr.api/Controllers/AccountController.cs, [1] [2] [3] [4] - Updated
SessionAuthenticationMiddlewareto resolveISessionServiceviaIServiceProviderins...
Automated canary build