question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow policy registries to be defined for keys of any type

See original GitHub issue

Is your feature request related to a specific problem? Or an existing feature? Please describe. Currently the PolicyRegistry class is tied to string keys, as opposed to being generic on the key. The result is that it’s not possible to create a PolicyRegistry with a different type as the key.

For example, if I want to key my policies by System.Uri, the only option I have is to implement IConcurrentPolicyRegistry<Uri> - which makes no sense because I don’t want or need any different semantics from what PolicyRegistry does, I just want it to allow me to use a different key type. I also don’t see anything on PolicyRegistry that is string-specific.

Describe your proposed or preferred solution:

  • Rename the current PolicyRegistry to KeyedPolicyRegistry<TKey>. Create a “new” PolicyRegistry class that inherits it, i.e. PolicyRegistry : KeyedPolicyRegistry<string>.

(Ideally we’d change PolicyRegistry to PolicyRegistry<TKey> and create a StringPolicyRegistry : PolicyRegistry<string>, except that would be a breaking change.)

  • PollyServiceCollectionExtensions should get 2 new generic overloads of AddPolicyRegistry that allow specifying the key type of the policy implementation. These will use KeyedPolicyRegistry<TKey>.

  • PollyHttpClientBuilderExtensions should get 3 new generic overloads of AddPolicyHandlerFromRegistry that handle the generic key scenario.

Describe any alternative options you’ve considered: Unending pain and torment, AKA implementing IConcurrentPolicyRegistry myself, registering a generic version of it myself, et cetera.

Any additional info? Nope.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
martintmkcommented, Jun 16, 2023

Yes, V8 now supports this scenario.

1reaction
IanKempcommented, Aug 10, 2021

It’s so nice to interact with someone who is passionate about the project and willing to take time to address/answer questions, no matter how daft they may be. @martincostello you are an exemplar of how interactions on GitHub should be - really, thank you. I wish I could say that my interactions with actual MS employees had generally been this helpful but alas…

(I also totally didn’t forget that generic types are not considered the same as non-generic types with the same name, despite doing .NET for over 15 years at this point. I swear I’m not getting old and forgetful…)

Anyhow, it sounds like you broadly agree with my proposal, so what’re the next steps? Do I need to write up a formal doc like dotnet/runtime requires, or does the Polly team need to discuss it further, or…? The reason I ask is that I’d be happy to contrib the code for this (to both Polly and ASP.NET Core) as it doesn’t appear to be a huge change in terms of effort, but obviously I’m not gonna do anything until you guys give the go-ahead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implementing Registry-based Policy
In this article · Select the registry location, naming and data types for keys · Select the values that can be assigned to...
Read more >
Can I use group policy to set the permissions on registry ...
Yes; from the Group Policy Object Editor, expand Computer Configuration > Windows Settings > Security Settings. You should see a Registry option ...
Read more >
Registry Key Security and Access Rights - Win32 apps
The valid access rights for registry keys include the DELETE, READ_CONTROL, WRITE_DAC, and WRITE_OWNER standard access rights. Registry keys do ...
Read more >
How to Add, Set, Delete, or Import Registry Keys via GPO
In this article, we will look at how to use Group Policy (GPO) to centrally create, modify, import, and delete any registry keys...
Read more >
Condition keys for Amazon Elastic Container Registry
Lists all of the available service-specific resources, actions, and condition keys that can be used in IAM policies to control access to Amazon...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found