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

PROPOSAL: Add interfaces to Polly #257

Closed
reisenberger opened this issue Jun 10, 2017 · 0 comments · Fixed by #263
Closed

PROPOSAL: Add interfaces to Polly #257

reisenberger opened this issue Jun 10, 2017 · 0 comments · Fixed by #263
Assignees
Labels
Milestone

Comments

@reisenberger
Copy link
Member

TL;DR Propose adding interfaces to Polly, in two segregated dimensions.

  • Execution-interfaces to define execution overloads common to all resilience strategies.
  • Orthogonal policy-kind-interfaces to define properties common to a kind of policy (eg the circuit state properties of all circuit-breaker policies).

Interface prototypes already visible in this branch: https://github.com/reisenberger/Polly/commits/feature/interfacesplusregistry

Background

Prior to Polly v5.0, the team was reluctant to introduce interfaces as the execute method overloads were known to be in rapid evolution. These have now stabilized.

Additionally, clear guidance can be given that custom policies should be implemented by extending the Policy base class (intend to wiki/blog example) and not by fulfilling interfaces. This mitigates one usual risk of introducing interfaces in an OSS project: that later evolving the interfaces risks user breakages.

Execution interfaces

Execution interfaces ISyncPolicy, IAsyncPolicy, ISyncPolicy<TResult> and IAsyncPolicy<TResult> would define the execution overloads available to policies targeting sync/async, and non-generic / generic calls respectively.

Recent blog posts outline why Polly has both non-generic and generic policies and separate sync and async policies.

Policy-kind interfaces

Orthogonal to the execution interfaces would be interfaces specific to each kind of Policy. These would define properties and methods common to that type of policy, whether the policy instance targeted sync or async executions.

For example, ICircuitBreakerPolicy defines

  • CircuitState CircuitState
  • Exception LastException
  • void Isolate()
  • void Reset()

with ICircuitBreakerPolicy<TResult> : ICircuitBreakerPolicy adding:

  • TResult LastHandledResult.

The benefit is that collections of these types of policies can then be managed - say, for monitoring purposes - as outlined by @christopherbahr in #205 .

BulkHead is the only other Polly policy which exposes state, so IBulkheadPolicy is the only other similar interface with content. However, other policy types would have similar empty marker interfaces (eg IRetryPolicy) for parity/completeness.

Registry support

The use of interfaces also supports the forthcoming PolicyRegistry feature, with a proposed empty IsPolicy marker interface identifying policies of all types.

@reisenberger reisenberger self-assigned this Jun 10, 2017
reisenberger added a commit to reisenberger/Polly that referenced this issue Jun 27, 2017
Adds interfaces to Polly.  Delivers App-vNext#257
@reisenberger reisenberger added this to the v5.2.0 milestone Jun 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant