-
Notifications
You must be signed in to change notification settings - Fork 722
Update OpenApi implementation to avoid reflection #1185
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
60 changes: 60 additions & 0 deletions
60
...re/WebApi/src/Asp.Versioning.OpenApi/DependencyInjection/AggregateKeyedServiceProvider.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
|
|
||
| #pragma warning disable IDE0130 | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| internal sealed class AggregateKeyedServiceProvider( IServiceProvider parent ) : IKeyedServiceProvider | ||
| { | ||
| private readonly IServiceProvider parent = parent; | ||
| private readonly List<IServiceProvider> providers = []; | ||
|
|
||
| public object? GetKeyedService( Type serviceType, object? serviceKey ) | ||
| { | ||
| if ( providers.Count == 0 ) | ||
| { | ||
| return parent.GetKeyedService( serviceType, serviceKey ); | ||
| } | ||
|
|
||
| foreach ( var provider in providers ) | ||
| { | ||
| if ( provider.GetKeyedService( serviceType, serviceKey ) is { } service ) | ||
| { | ||
| return service; | ||
| } | ||
| } | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
|
|
||
| return null; | ||
| } | ||
|
|
||
| public object GetRequiredKeyedService( Type serviceType, object? serviceKey ) | ||
| { | ||
| if ( providers.Count == 0 ) | ||
| { | ||
| return parent.GetRequiredKeyedService( serviceType, serviceKey ); | ||
| } | ||
|
|
||
| for ( int i = 0; i < providers.Count - 1; i++ ) | ||
| { | ||
| if ( providers[i].GetKeyedService( serviceType, serviceKey ) is { } service ) | ||
| { | ||
| return service; | ||
| } | ||
| } | ||
|
|
||
| return providers[providers.Count - 1].GetRequiredKeyedService( serviceType, serviceKey ); | ||
| } | ||
|
|
||
| public object? GetService( Type serviceType ) | ||
| => parent.GetService( serviceType ); | ||
|
|
||
| public void Add( IServiceCollection serviceCollection, IServiceCollection parentServiceCollection ) | ||
| { | ||
| foreach ( var descriptor in parentServiceCollection ) | ||
| { | ||
| serviceCollection.Add( descriptor ); | ||
| } | ||
|
|
||
| providers.Add( serviceCollection.BuildServiceProvider() ); | ||
| } | ||
| } | ||
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
63 changes: 0 additions & 63 deletions
63
...AspNetCore/WebApi/src/Asp.Versioning.OpenApi/DependencyInjection/KeyedServiceContainer.cs
This file was deleted.
Oops, something went wrong.
111 changes: 0 additions & 111 deletions
111
src/AspNetCore/WebApi/src/Asp.Versioning.OpenApi/Reflection/Class.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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.
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.
In case build-time generation was previously broken already (which I would expect it to), then the package should set these by default.
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.
This was definitely working before
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.
Good to know. I'll continue investigations then.
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.
Indeed. I updated PR description. It's working already on main and I'll try to look how can I make it work with the changes in this PR.