Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] generate subclient with public constructor #4983

Open
chunyu3 opened this issue Aug 9, 2024 · 1 comment
Open

[Feature] generate subclient with public constructor #4983

chunyu3 opened this issue Aug 9, 2024 · 1 comment

Comments

@chunyu3
Copy link
Member

chunyu3 commented Aug 9, 2024

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

@chunyu3
Copy link
Member Author

chunyu3 commented Aug 9, 2024

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.

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

No branches or pull requests

1 participant