I've resolved the issue by partial method.
My example is:
CampaignClient.cs
public partial class CampaignClient
{
partial void PrepareRequest(HttpClient request, ref string url);
partial void ProcessResponse(HttpClient request, HttpResponseMessage response);
//some codes...
}
CampaignClient.Extensions.cs - partial class:
public partial class CampaignClient
{
private readonly IRequestContext _requestContext;
private readonly IStartupConfiguration _startupConfiguration;
public CampaignClient(IRequestContext requestContext, IStartupConfiguration startupConfiguration)
{
_requestContext = requestContext;
_startupConfiguration = startupConfiguration;
}
partial void PrepareRequest(HttpClient request, ref string url)
{
request.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _requestContext.GetBearerTokenOrTriggerUnauthException());
}
}
Method override has saved me!