Skip to content

[Feature] generate subclient with public constructor #4983

@chunyu3

Description

@chunyu3

Current .NET SDK support two kinds of Client:

  • service Client
  • sub client : has no public constructor, it only can be created by the parent.

There is a third kind of client: a subclient with public constructor

Rule: When a subclient with public constructor:

  • the subclient name will suffix with Client.
  • The subclient will has additional public client constructor

example as following:

  • FaceServiceClient is the service client
  • FaceListClient is the subclient which has public client constructor
pubic partial class FaceServiceClient
{
    public FaceServiceClient(Uri endpoint, AzureKeyCredential credential, FaceServiceClientOptions options)
    {
            Argument.AssertNotNull(endpoint, nameof(endpoint));
            Argument.AssertNotNull(credential, nameof(credential));
            options ??= new AnomalyDetectorClientOptions();

            ClientDiagnostics = new ClientDiagnostics(options, true);
            _keyCredential = credential;
            _pipeline = HttpPipelineBuilder.Build(options, Array.Empty<HttpPipelinePolicy>(), new HttpPipelinePolicy[] { new AzureKeyCredentialPolicy(_keyCredential, AuthorizationHeader) }, new ResponseClassifier());
            _endpoint = endpoint;
            _apiVersion = options.Version;
    }
    FaceListClient GetFaceListClient()
    FaceLargeListClient GetLargeFaceListClient()
    PersonGroupClient GetPersonGroupClient()
    PersonLargeGroupClient GetLargePersonGroupClient()
}

public partial class FaceListClient
{
  //added public constructor
  public FaceListClient(Uri endpoint, AzureKeyCredential credential, FaceServiceClientOptions options)
  {
            Argument.AssertNotNull(endpoint, nameof(endpoint));
            Argument.AssertNotNull(credential, nameof(credential));
            options ??= new AnomalyDetectorClientOptions();

            ClientDiagnostics = new ClientDiagnostics(options, true);
            _keyCredential = credential;
            _pipeline = HttpPipelineBuilder.Build(options, Array.Empty<HttpPipelinePolicy>(), new HttpPipelinePolicy[] { new AzureKeyCredentialPolicy(_keyCredential, AuthorizationHeader) }, new ResponseClassifier());
            _endpoint = endpoint;
            _apiVersion = options.Version;
  }
  
  // interal construtor for Get accessor
  internal FaceServiceClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, AzureKeyCredential keyCredential, Uri endpoint, string apiVersion)
  {
      ClientDiagnostics = clientDiagnostics;
      _pipeline = pipeline;
      _keyCredential = keyCredential;
      _endpoint = endpoint;
      _apiVersion = apiVersion;
  }
  
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions