What are you wanting to achieve?
Hi,
I copied the code from from here:
https://www.pollydocs.org/advanced/dependency-injection.html#complex-pipeline-keys
Exactly into my project, but I kept getting "unable to find a resilience pipeline" exceptions.
What code or approach do you have so far?
When I looked through the code, specifically here:
|
if (_pipelines.TryGetValue(key, out pipeline)) |
public override bool TryGetPipeline(TKey key, [NotNullWhen(true)] out ResiliencePipeline? pipeline)
{
EnsureNotDisposed();
if (_pipelines.TryGetValue(key, out pipeline))
{
return true;
}
if (_builders.TryGetValue(key, out var configure))
{
pipeline = GetOrAddPipeline(key, configure);
return true;
}
pipeline = null;
return false;
}
It seems like if there is no pipeline defined with the key specified, like in your example:
ResiliencePipeline instanceA = pipelineProvider.GetPipeline(new MyPipelineKey(ResiliencePipelines.NetSuite, "instance-A"));
It should go ahead and look in the _builders dictionary and build a new pipeline, with that new key, adding it to _pipelines, correct?
But I think (?) the problem is that in your example, PipelineNameComparer.GetHashCode takes the InstanceName into account:
public sealed class PipelineNameComparer : IEqualityComparer<MyPipelineKey>
{
public bool Equals(MyPipelineKey x, MyPipelineKey y) => x.PipelineName == y.PipelineName;
public int GetHashCode(MyPipelineKey obj) => (obj.PipelineName, obj.InstanceName).GetHashCode(); // <--- InstanceName is respected here, but maybe it shouldn't be?
}
I think (?) paying attention to InstanceName breaks your example, because when the key search in _builders (above) happens, it won't find any values.
Further, if I change that GetHashCode function to look like this, things work as I'd expect:
public int GetHashCode(MyPipelineKey obj) => obj.PipelineName.GetHashCode();
I'm not sure what I might be breaking by making that change though, or if I'm just doing something else wrong somewhere.
Thoughts?
Additional context
No response
What are you wanting to achieve?
Hi,
I copied the code from from here:
https://www.pollydocs.org/advanced/dependency-injection.html#complex-pipeline-keys
Exactly into my project, but I kept getting "unable to find a resilience pipeline" exceptions.
What code or approach do you have so far?
When I looked through the code, specifically here:
Polly/src/Polly.Core/Registry/ResiliencePipelineRegistry.cs
Line 76 in 0e134b5
It seems like if there is no pipeline defined with the key specified, like in your example:
It should go ahead and look in the
_buildersdictionary and build a new pipeline, with that new key, adding it to_pipelines, correct?But I think (?) the problem is that in your example, PipelineNameComparer.GetHashCode takes the InstanceName into account:
I think (?) paying attention to InstanceName breaks your example, because when the key search in
_builders(above) happens, it won't find any values.Further, if I change that GetHashCode function to look like this, things work as I'd expect:
I'm not sure what I might be breaking by making that change though, or if I'm just doing something else wrong somewhere.
Thoughts?
Additional context
No response