Skip to content
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

Cleanup Microsoft.Extensions.Http.Resilience internals #4141

Merged
merged 12 commits into from
Jun 30, 2023

Conversation

martintmk
Copy link
Contributor

@martintmk martintmk commented Jun 29, 2023

Simplifying and dropping some unnecessary internal abstractions.

Changes:

  • Dropping some internal interfaces or turning them into abstract classes or just simple options.
  • Dropping additional dependencies (Polling, NamedSingletons) making this library leaner.
  • Enabling pooling of RequestMessageSnapshot.
Microsoft Reviewers: Open in CodeFlow

@martintmk martintmk self-assigned this Jun 29, 2023
@martintmk martintmk requested a review from geeknoid June 29, 2023 06:43
using System.Net.Http;

namespace Microsoft.Extensions.Http.Resilience.Internal;

/// <summary>
/// The provider that returns the strategy key from the request message.
/// </summary>
internal interface IStrategyKeyProvider
internal sealed class StrategyKeyOptions
Copy link
Member

@geeknoid geeknoid Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this type used in DI? If not, you could just be using Func<HttpRequestMessage, string> directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it comes from DI. This options class is just a holder for that delegate.

@@ -17,25 +18,22 @@ public static void SelectStrategyByAuthority(IServiceCollection services, string
{
var redactor = serviceProvider.GetRequiredService<IRedactorProvider>().GetRedactor(classification);

return new ByAuthorityStrategyKeyProvider(redactor);
return new ByAuthorityStrategyKeyProvider(redactor).GetStrategyKey;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps rename GetStrategyKey to just StrategyKey?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetStrategyKey is just a function that gets converted to a delegate. I think the name is ok here

@@ -115,4 +123,12 @@ private static IServiceCollection AddHedging(this IServiceCollection services, H

return services;
}

private class EmptyHandler : DelegatingHandler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Please keep one type per file. This makes it much easier to navigate the codebase - e.g., search for type in GitHub. Move to HttpClientFactory.EmptyHandler.cs.

Comment on lines 35 to 38
internal const string StandardClient = "Standard";

internal const string SingleHandlerClient = "SingleHandler";

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit]

Suggested change
internal const string StandardClient = "Standard";
internal const string SingleHandlerClient = "SingleHandler";
internal const string StandardClient = "Standard";
internal const string SingleHandlerClient = "SingleHandler";

@martintmk martintmk enabled auto-merge (squash) June 30, 2023 05:26
@martintmk martintmk merged commit 50330cb into main Jun 30, 2023
6 checks passed
@martintmk martintmk deleted the mtomka/cleanup-internals branch June 30, 2023 06:03
@ghost ghost added this to the 8.0 Preview7 milestone Jun 30, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jul 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants