Skip to content

smbc-digital/StockportGovUK.NetStandard.Gateways

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StockportGovUK.NetStandard.Gateways

💻🚪🌈
Wonders lie ahead
A common approach to talking to third party applications for StockportGovUK applications

External Links GitHub | NuGet

Built with ❤︎ by Stockport Council and contributors

Table of Contents

Features

  • Common approach: shared methods and a common fallback for gateways

Example

var response = await _gateway.GetCase(caseId);

Philosophy

We have always had need to use Gateways within our applications and had so many times we were copying and pasting the same files over to allow the same functionality. Finally enough was enough and we decided to encapsulate all of this functionality into A shared NuGet package with a set default for our applications

Service Gateways

Using a micro service architechture we wanted an easy way for services to expose their endpoints to any of our other services. In place or remembering the exact URL for a specific endpoint these gateways provide that information for the developer.

Within your application configuration you define the base URL for your service, allowing you to overide it per environment if you want to point to a test system.

This config is then used within the Gateway pacakge to route the request to the correct endpoint.

"IGatewayConfig": {
  "BaseUrl": "http://service.stockport.gov.uk/",
  "AuthToken": "TestToken",
  "EnablePollyPolicies": "false",
  "ProxyUrl": "127.0.0.1", (Optional)
  "ProxyPort":8080 (Optional)
}

Adding resilient clients (i.e. with circuit breaker) is now done via the gateways package (rather than through polly. To enable this behaviour add the following to startup.

services.AddHttpClient<IGateway, Gateway>(Configuration);

To use a gateway simply inject that gateway into the consumer.

public HomeController(IYourGatewayName gateway)

New gateways are constructed slightly differently, the following pattern is a gateway and example get request

    public class MyNewGateway : Gateway, IMyNewGateway
    {
        public MyNewGateway(HttpClient httpClient) : base(httpClient) 
        {
        }

        public async Task<HttpResponseMessage> DoSomethingAsync(string data)
        {
            var url = $"/api/v1/endpoint/{data}";
            return await GetAsync(url);
        }

Installation

$ dotnet add package StockportGovUK.NetStandard.Gateways

License

MIT

Releases

No releases published

Packages

No packages published

Languages