Show / Hide Table of Contents

Class HttpRestServiceClientExtension

Extension for HttpRestServiceClient.

Inheritance
System.Object
HttpRestServiceClientExtension
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ToString()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: StoneCo.Framework.DependencyInjection.Extension
Assembly: cs.temp.dll.dll
Syntax
public static class HttpRestServiceClientExtension

Methods

AddHttpRestServiceClientLog(IServiceCollection, IConfiguration)

This is a extension method to encapsulate dependency injection of the Communication Log.

In this extension, the options for Communication Log and the dependecy injection for HttpClient are set to call log API.

note

To use this extension, see the example below.

Declaration
public static IServiceCollection AddHttpRestServiceClientLog(this IServiceCollection services, IConfiguration configuration)
Parameters
Type Name Description
IServiceCollection services

The IServiceCollection to add the service to.

IConfiguration configuration

Represents a set of key/value application configuration properties.

Returns
Type Description
IServiceCollection

A reference to this instance after the operation has completed.

Examples

To use appsettings.json file.

{
  "Logs": {
    "Communication": {
      "Enable": true,
      "Host": "https://domain-of-api-log.com/"
    }
  }
}

To use configurations in database.

key = "Logs:Communication:Enable"; value = true;
key = "Logs:Communication:Host"; value = "https://domain-of-api-log.com/";

This sample should by applied on the infrastructure layer in DIFactory class.

public class DIFactory
{
    public static void ConfigureDI(IServiceCollection services, IConfiguration configuration)
    {
        services.AddHttpRestServiceClientLog(configuration);
    }
}
warning

This setting is required whenever you use HttpRestServiceClient and there is a need to create a communication log for each call.

Exceptions
Type Condition
System.ArgumentNullException

If the log is enable and host is null, an exception is thrown with message 'If communication logging is enabled, the host can not be null. for more information on how to enable or disable the HttpRestServiceClient communication log see the documentation at http://docfx.stone.com.br/StoneCo.Framework.Services.Client/StoneCo.Framework.Services.Client.HttpRestServiceClientExtension.html#methods .'.

AddScoped<TService, TImplementation>(IServiceCollection, String, String)

This is a extension method to encapsulate dependency injection of the HttpClient and HttpRestserviceClient.

Adds a scoped service of the type specified in TService with an implementation type specified in TImplementation to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection.

Declaration
public static IServiceCollection AddScoped<TService, TImplementation>(this IServiceCollection services, string name, string baseAddress)
    where TService : class where TImplementation : class, TService
Parameters
Type Name Description
IServiceCollection services

The IServiceCollection to add the service to.

System.String name

The logical name of the client to create.

System.String baseAddress

The URL that identify host of the HTTP Rest API call.

Returns
Type Description
IServiceCollection

A reference to this instance after the operation has completed.

Type Parameters
Name Description
TService

Interface of the connectors or clients provided by Domains or Microservices.

TImplementation

Concrete class of the connectors or clients provided by Domains or Microservices that implement the TService.

Examples

This sample should by applied on the infrastructure layer in DIFactory class.

public class DIFactory
{
    public static void ConfigureDI(IServiceCollection services, IConfiguration configuration)
    {
        services.AddScoped<IFooConnector, FooConnector>("FooConnector", "https://domain-of-api.com/");
    }
}
Back to top Generated by DocFX