# Retry policy in HttpClientManagementConnection (Auth0 .NET SDK)

**URL:** <https://community.auth0.com/t/retry-policy-in-httpclientmanagementconnection-auth0-net-sdk/64652>\
**Category:** Get Help\
**Tags:** auth0-sdk, management-api, auth0\
**Created:** [June 17, 2021, 12:45pm UTC](https://community.auth0.com/t/retry-policy-in-httpclientmanagementconnection-auth0-net-sdk/64652 "2021-06-17T12:45:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![adeliab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adeliab/32/12951_2.png) [@adeliab](https://community.auth0.com/u/adeliab)\
**Post date:** [June 17, 2021, 12:45pm UTC](https://community.auth0.com/t/retry-policy-in-httpclientmanagementconnection-auth0-net-sdk/64652/1 "2021-06-17T12:45:41Z")

</div>

Hi,

I’m looking into using the Auth0 .NET SDK to access the management API. The operations that I’ll need to access are get user and create user for now. Looking at the SDK documentation: [Documentation](https://auth0.github.io/auth0.net/) I’m wondering if it’s possible to apply Polly retry policy to the HttpClient used by the HttpClientManagementConnection. From this documentation, [Class HttpClientManagementConnection](http://auth0.github.io/auth0.net/api/Auth0.ManagementApi.HttpClientManagementConnection.html) it seems that the constructor receives an HttpClient object.

I wonder if the following code on Startup would enforce retry policy to the HttpClient used by the HttpClientManagementConnection. It uses the AddHttpClient extension from .NET Core:

```auto
services.AddSingleton<IManagementConnection, HttpClientManagementConnection>();
services.AddHttpClient<IManagementConnection, HttpClientManagementConnection>().AddPolicyHandler(GetRetryPolicy());

```

I’m not sure how to test if the retry is working

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [June 18, 2021, 8:40am UTC](https://community.auth0.com/t/retry-policy-in-httpclientmanagementconnection-auth0-net-sdk/64652/2 "2021-06-18T08:40:36Z")

</div>

Will try to research that but I’m not .NET guy, maybe someone else from the community will be able share some tips

---

<div class="post-metadata">

**Author:** ![adeliab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adeliab/32/12951_2.png) [@adeliab](https://community.auth0.com/u/adeliab)\
**Post date:** [June 18, 2021, 11:28am UTC](https://community.auth0.com/t/retry-policy-in-httpclientmanagementconnection-auth0-net-sdk/64652/3 "2021-06-18T11:28:50Z")

</div>

I did more test and apparently injecting it like that doesn’t work. There’s no retry happening… i need to figure out how to inject the HttpClient into ManagementConnection in another way

---

<div class="post-metadata">

**Author:** ![adeliab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adeliab/32/12951_2.png) [@adeliab](https://community.auth0.com/u/adeliab)\
**Post date:** [June 18, 2021, 12:36pm UTC](https://community.auth0.com/t/retry-policy-in-httpclientmanagementconnection-auth0-net-sdk/64652/4 "2021-06-18T12:36:47Z")

</div>

Using Func in dependency injection and injecting the HttpClient there seems to work

```auto
services.AddTransient<IUserProvider, UserProvider>();
services
                .AddHttpClient(UserProviderHttpClientName)
                .AddPolicyHandler((services, request) => GetRetryPolicy<UserProvider>(services, request));
services.AddTransient<IManagementConnection>((serviceProvider) =>
{
                var httpClientFactory = serviceProvider.GetService<IHttpClientFactory>();
                var httpClient = httpClientFactory.CreateClient(UserProviderHttpClientName);
                return new HttpClientManagementConnection(httpClient);
});

```

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [June 18, 2021, 1:22pm UTC](https://community.auth0.com/t/retry-policy-in-httpclientmanagementconnection-auth0-net-sdk/64652/5 "2021-06-18T13:22:42Z")

</div>

Glad you have figured it out and thanks for sharing with the rest of community!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [June 25, 2021, 11:38am UTC](https://community.auth0.com/t/retry-policy-in-httpclientmanagementconnection-auth0-net-sdk/64652/6 "2021-06-25T11:38:33Z")

</div>


