pact-net icon indicating copy to clipboard operation
pact-net copied to clipboard

Multiple provider state middleware

Open karthik-murali-airelogic opened this issue 1 year ago • 1 comments
trafficstars

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.

mefellows avatar Aug 21 '24 11:08 mefellows

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 👍

adamrodger avatar Aug 31 '24 09:08 adamrodger