diff --git a/src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs b/src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs
index c1445ac52..021d6c85a 100644
--- a/src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs
+++ b/src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs
@@ -13,6 +13,7 @@ namespace Microsoft.Graph
using System.Threading;
using Azure.Core;
using Microsoft.Graph.Authentication;
+ using Microsoft.Kiota.Abstractions;
using Microsoft.Kiota.Abstractions.Authentication;
using Microsoft.Kiota.Http.HttpClientLibrary;
using Microsoft.Kiota.Http.HttpClientLibrary.Middleware;
@@ -170,7 +171,21 @@ public static HttpClient Create(
///
public static IList CreateDefaultHandlers(GraphClientOptions graphClientOptions = null)
{
- var handlers = KiotaClientFactory.CreateDefaultHandlers();
+ return CreateDefaultHandlers(graphClientOptions, null);
+ }
+
+ ///
+ /// Create a default set of middleware for calling Microsoft Graph, letting callers configure the
+ /// underlying Kiota handlers (for example a custom )
+ /// without having to remove and reinsert a handler afterwards.
+ ///
+ /// The to use with the client
+ /// The request options to configure the default Kiota handlers with. See
+ /// for the handlers that read these options.
+ ///
+ public static IList CreateDefaultHandlers(GraphClientOptions graphClientOptions, IRequestOption[] optionsForHandlers)
+ {
+ var handlers = KiotaClientFactory.CreateDefaultHandlers(optionsForHandlers);
handlers.Add(new GraphTelemetryHandler(graphClientOptions));// add the telemetry handler last.
return handlers;
diff --git a/tests/Microsoft.Graph.DotnetCore.Core.Test/Requests/GraphClientFactoryTests.cs b/tests/Microsoft.Graph.DotnetCore.Core.Test/Requests/GraphClientFactoryTests.cs
index d4d9c7f12..7fdbf6811 100644
--- a/tests/Microsoft.Graph.DotnetCore.Core.Test/Requests/GraphClientFactoryTests.cs
+++ b/tests/Microsoft.Graph.DotnetCore.Core.Test/Requests/GraphClientFactoryTests.cs
@@ -10,9 +10,11 @@ namespace Microsoft.Graph.DotnetCore.Core.Test.Requests
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
+ using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
+ using Microsoft.Kiota.Abstractions;
using Microsoft.Kiota.Abstractions.Authentication;
using Microsoft.Kiota.Http.HttpClientLibrary.Middleware;
using Microsoft.Kiota.Http.HttpClientLibrary.Middleware.Options;
@@ -148,6 +150,30 @@ public void CreatePipeline_Should_Throw_Exception_With_Duplicate_Handlers()
Assert.Contains($"{typeof(GraphTelemetryHandler)} has a duplicate handler.", exception.Message);
}
+ [Fact]
+ public void CreateDefaultHandlers_Should_Forward_RetryHandlerOption_To_RetryHandler()
+ {
+ var retryOption = new RetryHandlerOption
+ {
+ MaxRetry = 7,
+ Delay = 3
+ };
+
+ var defaultHandlers = GraphClientFactory.CreateDefaultHandlers(new GraphClientOptions(), new IRequestOption[] { retryOption });
+
+ var retryHandler = defaultHandlers.OfType().Single();
+
+ // RetryHandler.RetryOption is internal to the Kiota library, so we reach it with reflection
+ // to prove the option we passed in is the one the handler ended up with.
+ var retryOptionProperty = typeof(RetryHandler).GetProperty("RetryOption", BindingFlags.NonPublic | BindingFlags.Instance);
+ Assert.NotNull(retryOptionProperty);
+ var actualRetryOption = (RetryHandlerOption)retryOptionProperty.GetValue(retryHandler);
+
+ Assert.Same(retryOption, actualRetryOption);
+ Assert.Equal(7, actualRetryOption.MaxRetry);
+ Assert.Equal(3, actualRetryOption.Delay);
+ }
+
[Fact]
public void CreateClient_CustomHttpHandlingBehaviors()
{