title: How to use DI with Microsoft Graph
body: <p>I have a .net web api core project and I will call microsoft graph</p>
  <p>So I created a configuration class:</p>
  <pre><code>public class GraphConfiguration
      {
          public static void Configure(IServiceCollection services, IConfiguration configuration)
          {
              //Look at appsettings.Development.json | https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.1
              var graphConfig = new AppSettingsSection();
              configuration.GetSection(&quot;AzureAD&quot;).Bind(graphConfig);
  
              IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
                  .Create(graphConfig.ClientId)
                  .WithTenantId(graphConfig.TenantId)
                  .WithClientSecret(graphConfig.ClientSecret)
                  .Build();
                  
              ClientCredentialProvider authenticationProvider = new ClientCredentialProvider(confidentialClientApplication);
              GraphServiceClient graphServiceClient = new GraphServiceClient(authenticationProvider);     
  
          }
      }
  </code></pre>
  <p>and in my controller I have this:</p>
  <pre><code> public class UserController : ControllerBase
      {
          private TelemetryClient telemetry;
          private readonly ICosmosStore&lt;Partner&gt; _partnerCosmosStore;
          private readonly GraphServiceClient _graphServiceClient;
  
  
          // Use constructor injection to get a TelemetryClient instance.
          public UserController(TelemetryClient telemetry,ICosmosStore&lt;Partner&gt; partnerCosmosStore, GraphServiceClient graphServiceClient)
          {
              this.telemetry = telemetry;
               _partnerCosmosStore = partnerCosmosStore; 
               _graphServiceClient = graphServiceClient;          
          }
  
          /// &lt;summary&gt;
          /// Gets all partners
          /// &lt;/summary&gt;
          /// &lt;returns&gt;&lt;/returns&gt;
          [HttpGet]
          public async Task&lt;ActionResult&gt; GetUsers()
          {
              this.telemetry.TrackEvent(&quot;GetPartners&quot;);
          
              try
              {
                  var me = await _graphServiceClient.Me.Request().WithForceRefresh(true).GetAsync();
                  return Ok(me);
              }
              catch (Exception ex)
              {
                  string guid = Guid.NewGuid().ToString();
                  var dt = new Dictionary&lt;string, string&gt;
                  {
                      { &quot;Error Lulo: &quot;, guid }
                  };
                  telemetry.TrackException(ex, dt);
                  return BadRequest(&quot;Error Lulo: &quot; + guid);
              }
          }      
      }
  </code></pre>
  <p>But I think I am missing a step here, in Startupcs. how do I actually inject it in all controllers?</p>