Basic configuration
Like EMG.HubSpot.Client, this library also adds extension methods to IServiceCollection to quickly register all the needed components.
var services = new ServiceCollection();
services.AddHubSpot(hs =>
{
// ... here goes the configuration part.
});The hs variable passed to the configuration delegate is an instance of type IHubSpotConfigurator and expose methods that can be used to:
configure the underlying
IHubSpotClientregister internal services.
Additional extension methods to the IHubSpotConfigurator type are available and can be added.
Configure the HubSpot client
While being a higher-layer library, this library allows full access to the customization of the HubSpot client as described earlier.
This can be achieved using the ConfigureHubSpotClient method.
In the snippet below, we're registering all the customizations we added earlier.
services.AddHubSpot(hs =>
{
hs.ConfigureHubSpotClient(client => client
.SetBaseAddress(new Uri("https://localhost.temp"))
.UseOAuthAuthentication(configuration.GetSection("HubSpot"))
.ConfigureSerialization(settings => settings.Formatting = Newtonsoft.Json.Formatting.Indented)
.ConfigureHttpClient(http => http.DefaultRequestHeaders.Add("X-CustomHeader", "my value"))
.ConfigureHttpClientBuilder(builder => builder
.AddHttpMessageHandler<HttpClientXRayTracingHandler>()
.AddPolicyHandler(GetRetryPolicy())));
});Authentication
Since HubSpot always require any of the two supported authentication methods, convenience methods are offered to set up the authentication method without the need of using ConfigureHubSpotClient.
services.AddHubSpot(hs =>
{
hs.UseOAuthAuthentication(configuration.GetSection("HubSpot"));
});
services.AddHubSpot(hs =>
{
hs.UseApiKeyAuthentication(configuration.GetSection("HubSpot"));
});The same assumptions done earlier apply.
Last updated
Was this helpful?