pact-net
pact-net copied to clipboard
Multiple provider state middleware
Is it possible to register multiple Provider state middleware as follows?
public override void Configure(IApplicationBuilder app)
{
app.UseMiddleware<TokenReplacementMiddleware>();
app.UseMiddleware<ProviderStateMiddlewareA>();
app.UseMiddleware<ProviderStateMiddlewareB>();
base.Configure(app);
}
ProviderStateMiddlewareA would cater to consumer A's states and ProviderStateMiddlewareB to consumer B. When I tried this, only the first middleware ProviderStateMiddlewareA would work.
Provider State Url is registered as below and both the middleware above uses this URL in their InvokeAsync.
.WithProviderStateUrl(new Uri(fixture.ServerUri, "/provider-states"))
I am using PactNet 4.5.0.
This is not so much as a Pact issue as a "how does middleware work" issue. I'm no .NET expert, but I suspect if ProviderStateMiddlewareA doesn't know how to respond to a request, it should just forward to the next middleware and so on. If no middleware accepts the request, then it would fail.
If each middleware consumes the path and doesn't forward on requests it can't handle, then I suspect that's the problem.
To answer the question semi-directly, Pact only supports a single URL to send provider state requests to.
That's correct @mefellows 👍 Each middleware would need to know which requests it can handle, and forward on to the next one if it can't.
Like you say, that's not really a Pact concern though, so I'll close this one 👍