/// <summary> /// Default constructor base to set options and HttpRestServiceClient. /// </summary> /// <param name="options">The options design pattern used in SampleServiceClient.</param> /// <param name="httpRestServiceClient">Interface with the default methods and properties to be used for all HTTP Rest calls.</param> protected SampleServiceClientBase(IOptionsSnapshot <SampleServiceClientOptions> options, IHttpRestServiceClient httpRestServiceClient) { HttpRestServiceClient = httpRestServiceClient; Options = options; if (string.IsNullOrWhiteSpace(options.Value?.AuthorizationToken)) { throw new ArgumentNullException("SampleServiceClientOptions.AuthorizationToken", "The token of authorization cannot be null."); } if (string.IsNullOrWhiteSpace(options.Value?.BaseAddress)) { throw new ArgumentNullException("SampleServiceClientOptions.BaseAddress", "The base address cannot be null."); } if (string.IsNullOrWhiteSpace(options.Value?.Name)) { throw new ArgumentNullException("SampleServiceClientOptions.Name", "The name of client cannot be null."); } AuthorizationToken = options.Value.AuthorizationToken; }
/// <summary> /// Default constructor to set options and HttpRestServiceClient. /// </summary> /// <param name="options">The options design pattern used in SampleServiceClient.</param> /// <param name="httpRestServiceClient">Interface with the default methods and properties to be used for all HTTP Rest calls.</param> /// <param name="configuration">Represents a set of key/value application configuration properties.</param> /// <example> /// Finally, follow the example of how to use the client. /// <code> /// public class Bar /// { /// private ISampleServiceClient SampleServiceClient { get; } /// /// public Bar(ISampleServiceClient sampleServiceClient) => SampleServiceClient = sampleServiceClient; /// /// public async Task NewAsync(string name) /// { /// var protocol = Guid.NewGuid().ToString("N"); /// var request = new NewSampleRequestMessage /// { /// Name = "Jhon" /// } /// /// request.AddHeader(Headers.Protocol, protocol); /// /// var result = await SampleServiceClient.NewAsync(request); /// } /// } /// </code> /// </example> public SampleServiceClient(IOptionsSnapshot <SampleServiceClientOptions> options, IHttpRestServiceClient httpRestServiceClient, IConfiguration configuration) : base(options, httpRestServiceClient) => ApplicationName = configuration.GetSection("Host:ApplicationName")?.Value;