예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var graphOptions = new MSGraphOptions();

            Configuration.Bind("MSGraph", graphOptions);

            services.AddSingleton(graphOptions);

            IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
                                                                           .Create(graphOptions.GraphClientId)
                                                                           .WithTenantId(graphOptions.TenantID)
                                                                           .WithClientSecret(graphOptions.GraphClientSecret)
                                                                           .Build();

            var mSGraphauthProvider = new ClientCredentialProvider(confidentialClientApplication, "https://graph.microsoft.com/.default");

            services.AddSingleton(mSGraphauthProvider);

            services.AddHttpClient <IMSGraphServiceClientAdaptor, MSGraphServiceClientAdaptor>(PolicyNames.GraphHttpClient)
            .AddPolicyHandler(HttpPolicies.GetRetryPolicy());

            services.AddSingleton <IMSGraphServiceClientAdaptor, MSGraphServiceClientAdaptor>();

            services.AddControllers();
        }
 /// <summary>
 /// Simply adds all the http policies to HttpClient instance
 /// </summary>
 /// <param name="httpClientBuilder"></param>
 /// <returns></returns>
 public static IHttpClientBuilder AddPolicyHandlers(this IHttpClientBuilder httpClientBuilder)
 {
     return(httpClientBuilder
            .AddPolicyHandler(HttpPolicies.GetRetryPolicy())
            .AddPolicyHandler(HttpPolicies.GetCircuitBreakerPolicy()));
 }