1- // ------------------------------------------------------------------------------
1+ // ------------------------------------------------------------------------------
22// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
33// ------------------------------------------------------------------------------
44namespace Microsoft . Graph
@@ -8,29 +8,14 @@ namespace Microsoft.Graph
88 using System . Linq ;
99 using System . Net ;
1010 using System . Net . Http ;
11- using System . Reflection ;
1211 using System . Net . Http . Headers ;
1312 using Microsoft . Kiota . Http . HttpClientLibrary . Middleware ;
14- using Microsoft . Kiota . Abstractions . Authentication ;
13+
1514 /// <summary>
1615 /// GraphClientFactory class to create the HTTP client
1716 /// </summary>
1817 public static class GraphClientFactory
1918 {
20- /// The key for the SDK version header.
21- private static readonly string SdkVersionHeaderName = CoreConstants . Headers . SdkVersionHeaderName ;
22-
23- /// The version for current assembly.
24- private static Version assemblyVersion = typeof ( GraphClientFactory ) . GetTypeInfo ( ) . Assembly . GetName ( ) . Version ;
25-
26- /// The value for the SDK version header.
27- private static string SdkVersionHeaderValue = string . Format (
28- CoreConstants . Headers . SdkVersionHeaderValueFormatString ,
29- "Graph" ,
30- assemblyVersion . Major ,
31- assemblyVersion . Minor ,
32- assemblyVersion . Build ) ;
33-
3419 /// The default value for the overall request timeout.
3520 private static readonly TimeSpan defaultTimeout = TimeSpan . FromSeconds ( 100 ) ;
3621
@@ -60,17 +45,19 @@ public static class GraphClientFactory
6045 /// </summary>
6146 /// <param name="version">The graph version to use.</param>
6247 /// <param name="nationalCloud">The national cloud endpoint to use.</param>
48+ /// <param name="graphClientOptions">The <see cref="GraphClientOptions"/> to use with the client</param>
6349 /// <param name="proxy">The proxy to be used with created client.</param>
6450 /// <param name="finalHandler">The last HttpMessageHandler to HTTP calls.
6551 /// The default implementation creates a new instance of <see cref="HttpClientHandler"/> for each HttpClient.</param>
6652 /// <returns></returns>
6753 public static HttpClient Create (
54+ GraphClientOptions graphClientOptions = null ,
6855 string version = "v1.0" ,
6956 string nationalCloud = Global_Cloud ,
7057 IWebProxy proxy = null ,
7158 HttpMessageHandler finalHandler = null )
7259 {
73- IList < DelegatingHandler > handlers = CreateDefaultHandlers ( ) ;
60+ IList < DelegatingHandler > handlers = CreateDefaultHandlers ( graphClientOptions ) ;
7461 return Create ( handlers , version , nationalCloud , proxy , finalHandler ) ;
7562 }
7663
@@ -109,7 +96,6 @@ public static HttpClient Create(
10996
11097 var pipelineWithFlags = CreatePipelineWithFeatureFlags ( handlers , finalHandler ) ;
11198 HttpClient client = new HttpClient ( pipelineWithFlags . Pipeline ) ;
112- client . DefaultRequestHeaders . Add ( SdkVersionHeaderName , SdkVersionHeaderValue ) ;
11399 client . SetFeatureFlag ( pipelineWithFlags . FeatureFlags ) ;
114100 client . Timeout = defaultTimeout ;
115101 client . BaseAddress = DetermineBaseAddress ( nationalCloud , version ) ;
@@ -120,10 +106,12 @@ public static HttpClient Create(
120106 /// <summary>
121107 /// Create a default set of middleware for calling Microsoft Graph
122108 /// </summary>
109+ /// <param name="graphClientOptions">The <see cref="GraphClientOptions"/> to use with the client</param>
123110 /// <returns></returns>
124- public static IList < DelegatingHandler > CreateDefaultHandlers ( )
111+ public static IList < DelegatingHandler > CreateDefaultHandlers ( GraphClientOptions graphClientOptions = null )
125112 {
126113 return new List < DelegatingHandler > {
114+ new GraphTelemetryHandler ( graphClientOptions ) ,
127115 new OdataQueryHandler ( ) ,
128116 new CompressionHandler ( ) ,
129117 new RetryHandler ( ) ,
0 commit comments