This is my first question here so pardon me if I am not following the full guidelines.
We have micro services architecture and nearly 15 .Net Services all accessible via REST Api. (Combination of WCF and WebAPI).
Most of the services accept two security related headers in every http call.
The presence of such headers is done via intercepting WCF or Web API calls at present
Now we have started creating .Net based Service Client (internally using RestSharp) and make them availabel via NuGet because we want to make the integration easy.
So we now have a dilemma about how to go about passing this security related headers into each method of such Service Client.?
The options we are thinking about are
- Have an additional parameters in each method so that consumers of our service client can pass the security headers
- Have a tracing context interface injected into Service Client constructor so that each methods can inspect it and responsibility of setting the correct tracing context will be with consumers. A bit muddy as each method can be called with different values for security headers
Following is a code snippet we are thinking
public class TestResponse
{
public bool Success { get; set; }
}
public class TestRequest
{
public string Name { get; set; }
}
public interface ITestServiceClient
{
TestResponse GetTest(TestRequest testRequest);
}
public class TestServiceClient : ITestServiceClient
{
private readonly Uri _serviceBaseUrl;
public TestServiceClient(Uri serviceBaseUrl)
{
_serviceBaseUrl = serviceBaseUrl;
}
// We would need to pass the required header as part of this method call
public TestResponse GetTest(TestRequest testRequest)
{
//RestSharp call here to actual service HTTP url
return new TestResponse();
}
}
What's the best way to achieve this?
Thanks