fix: resolve ITrainAuthorizationService inside a scope#29
Merged
Conversation
AuthorizationRegistrationValidator resolved ITrainAuthorizationService directly off the IServiceProvider passed into its constructor. In production hosts that service is registered Scoped (as Trax.Api does); resolving a Scoped service from the root provider trips ServiceProvider's scope validation whenever it is enabled (dev-mode ASP.NET Core, WebApplicationFactory E2E tests, etc.) with the error "Cannot resolve scoped service 'ITrainAuthorizationService' from root provider." Create a scope before the resolution and dispose it immediately after. The validator only needs to confirm the service is registered, not hold a reference to it past startup. Adds a regression test that registers the service Scoped and builds the provider with ValidateScopes = true.
|
This PR is included in version 1.16.1 |
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.
Summary
Why this wasn't caught in #28
The existing validator tests register a mocked `ITrainAuthorizationService` as Singleton, so scope validation never fires. Trax.Api registers the real service Scoped. JobHunt / GameServer E2E suites (which use `WebApplicationFactory`, which enables `ValidateScopes` by default) caught it downstream.
Test plan