TSYS-Merchant / stumps

Apache License 2.0
3 stars 3 forks source link

Use Factory to Return HTTP Response within a Stump #92

Closed mwmharrington closed 6 years ago

mwmharrington commented 6 years ago

Refactor Stumps to use a factory to generate an HTTP response for a stump rather than having a Stump directly tied to a static response. This allows Stumps to dynamically modify the response. Further, providing the originating HTTP request to the factory can allow the response to be modified based on the content of the incoming request.

Example Code

Before

class Stump { 

  // Other Code Here ...

  public IStumpsHttpResponse Response
  {
      get => _response;
      set => _response = value ?? throw new ArgumentNullException(nameof(value));
  }
}

After

class Stump { 

  // Other Code Here ...

  public IHttpResponseFactory ResponseFactory
  {
      get => _responseFactory;
      set => _responseFactory = value ?? throw new ArgumentNullException(nameof(value));
  }
}

interface IHttpResponseFactory { IStumpsHttpResponse CreateResponse(IStumpsHttpRequest request); }

mwmharrington commented 6 years ago

Completed and added to v0.4

mwmharrington commented 6 years ago

This has been updated with #93 wherein the interface is now called IStumpResponseFactory.