0

As I understand it a Policy in Polly is thread safe and there should be only one shared instance of it.

So I guess that it would be safe to inject a singleton CB Policy in the controllers that needs to know if the circuit are open.

Am I right?

Martin Andersen
  • 2,460
  • 2
  • 38
  • 66

1 Answers1

0

As I understand it a Policy in Polly is thread safe

Correct.

and there should be only one shared instance of it.

I guess the statement 'should be only one shared instance' needs to be qualified somehow with 'shared across what?'. The correct scoping is share a policy instance across call sites you want to break in common - typically, call sites calling the same downstream system.

  • Share the same breaker policy instance across call sites when you want those call sites to break in common - for instance they are calls to a common downstream dependency.
  • Don't share a breaker instance across call sites (use different instances) when you want those call sites to have independent circuit state and break independently.

So I guess that it would be safe to inject a singleton CB Policy in the controllers that needs to know if the circuit are open.

It would be safe. Share or don't share the same instance across call sites as discussed above.

These questions/answers 1 2 and this in the Polly wiki are related.

mountain traveller
  • 7,591
  • 33
  • 38