Skip to content

Commit

Permalink
feat: Generate calls to GetEffectiveSettings in the client builder
Browse files Browse the repository at this point in the history
This will allow API key support to be introduced through partial classes.

Requires googleapis/gax-dotnet#732 to be merged and released.
  • Loading branch information
jskeet committed Jan 23, 2024
1 parent 8ebd129 commit c8ca0c4
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,27 @@ private MethodDeclarationSyntax BuildImpl()
{
var callInvoker = Local(_ctx.Type<CallInvoker>(), "callInvoker");
var logger = Property(Public, _ctx.Type<ILogger>(), nameof(ClientBuilderBase<string>.Logger));
var settingsClone = IdentifierName("Settings").Call("Clone", conditional: true)();
var effectiveSettings = This.Call("GetEffectiveSettings")(settingsClone);
return Method(Private, _ctx.Type(_svc.ClientAbstractTyp), "BuildImpl")()
.WithBody(
This.Call("Validate")(),
callInvoker.WithInitializer(This.Call("CreateCallInvoker")()),
Return(_ctx.Type(_svc.ClientAbstractTyp).Call("Create")(callInvoker, Settings(), logger)));
Return(_ctx.Type(_svc.ClientAbstractTyp).Call("Create")(callInvoker, effectiveSettings, logger)));
}

private MethodDeclarationSyntax BuildAsyncImpl()
{
var cancellationToken = Parameter(_ctx.Type<CancellationToken>(), "cancellationToken");
var callInvoker = Local(_ctx.Type<CallInvoker>(), "callInvoker");
var logger = Property(Public, _ctx.Type<ILogger>(), nameof(ClientBuilderBase<string>.Logger));
var settingsClone = IdentifierName("Settings").Call("Clone", conditional: true)();
var effectiveSettings = This.Call("GetEffectiveSettings")(settingsClone);
return Method(Private | Async, _ctx.Type(Typ.Generic(typeof(Task<>), _svc.ClientAbstractTyp)), "BuildAsyncImpl")(cancellationToken)
.WithBody(
This.Call("Validate")(),
callInvoker.WithInitializer(Await(This.Call("CreateCallInvokerAsync")(cancellationToken).ConfigureAwait())),
Return(_ctx.Type(_svc.ClientAbstractTyp).Call("Create")(callInvoker, Settings(), logger)));
Return(_ctx.Type(_svc.ClientAbstractTyp).Call("Create")(callInvoker, effectiveSettings, logger)));
}

private MethodDeclarationSyntax GetChannelPool() =>
Expand Down

0 comments on commit c8ca0c4

Please sign in to comment.