[Feature Request] Keyed service GraphServiceClient
Is your feature request related to a problem? Please describe. I have an application that connect to multiple tenants. I would like to be able to retrieve a GraphServiceClient configured for a given tenant. This should be similar to serviceName for DownstreamApi
Describe the solution you'd like
services
.Configure<MicrosoftIdentityApplicationOptions>("foo", configuration.GetSection("AzureAds:foo")
.Configure<MicrosoftIdentityApplicationOptions>("bar", configuration.GetSection("AzureAds:bar")
.AddMicrosoftGraph("foo", configuration.GetSection("Tenants:foo"))
.AddMicrosoftGraph("bar", configuration.GetSection("Tenants:bar"));
// or
services
.AddMicrosoftGraphs(configuration.GetSection("Tenants"))
public class MyService([FromKeyedServices("Foo")] GraphServiceClient graphClient) {}
// or more dynamic
serviceProvider.GetRequiredKeyedService<GraphServiceClient>(tenant);
Describe alternatives you've considered
I tried do it myself but utility classes like GraphAuthenticationProvider and GraphClientFactory are internal.
Additional context N/A
You could configure your GraphServiceClients manually with TokenCredentials from Azure.Identity and then use the allready proposed KeyedService feature for dependency injection to achive this.
If i understand you correctly you basically want this beeing integrated into the Configuration wrapper - right?
You could configure your GraphServiceClients manually with
TokenCredentialsfrom Azure.Identity and then use the allready proposed KeyedService feature for dependency injection to achive this.If i understand you correctly you basically want this beeing integrated into the Configuration wrapper - right?
Yes, that's exactly that.