Azure / Microsoft.Azure.StackExchangeRedis

Azure-specific wrapper for the StackExchange.Redis client library
MIT License
17 stars 14 forks source link

Can ConfigureForAzureAsync et al be made synchronous? #50

Closed twsouthwick closed 5 months ago

twsouthwick commented 6 months ago

I have to call the options.ConfigureForAzureAsync in a synchronous method due to the startup configuration I have. Most options are configured in a non-async way so this feels out of place and requires me to either refactor a bunch or do sync-over-async. I haven't dived into what's going on there, but is there a way this can be deferred in a way to allow the configuration to be synchronous?

Here's the code that I have:

https://github.com/Azure/reliable-web-app-pattern-dotnet/blob/414391036e67fcf356cfe6622bb37c9cca2651d3/src/Relecloud.Web.CallCenter.Api/AzureExtensions.cs#L20-L29

For context, this is in an app still using the Startup configuration ASP.NET Core pattern. In order to initialize it purely async, I'll probably need to refactor to the new builder pattern.

philon-msft commented 5 months ago

Retrieving an access token from MS Entra is an async operation that needs to be completed before the connection to Redis can be established, so there's not much room to defer it. Using sync-over-async is a suitable approach until your app initialization can be moved to a new async pattern.