Skip to content
This repository was archived by the owner on Jun 16, 2026. It is now read-only.
This repository was archived by the owner on Jun 16, 2026. It is now read-only.

[Feature] generate subclient with public constructor #4983

Closed

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;
  }
  
}

Activity

  1. chunyu3 commented on Aug 9, 2024

    @chunyu3
    MemberAuthor

    explore augmenting the @clientInitializer decorator onto a namespace or interface which could convert it to a SubClient with a public initializer
    Codegen will generate this client as above:

    • client name suffix with Client
    • add an extra public client constructor which can initialize itself

    Then there will be three kind of client:

    • service Client

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

    • sub client with public constructor: it has public constructor, it can be created by parent, also can be created by itself.

  2. removed their assignment
    on May 8, 2025
  3. JoshLove-msft commented on Mar 2, 2026

    @JoshLove-msft
    Member

    This is done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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