Last active
July 3, 2022 20:06
-
-
Save MirzaMerdovic/67a5daca81076c9ce4627d04c05137bd to your computer and use it in GitHub Desktop.
Snippet for: Azure App Configuration as a configuration provider in .NET Core apps - Part 3: Hot-Reload (https://medium.com/p/de398e009553)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.MapPost( | |
"/refresh", | |
async ( | |
[FromBody] Azure.Messaging.EventGrid.EventGridEvent[] request, | |
[FromServices] IConfigurationRefresherProvider refreshProvider) => | |
{ | |
var eg = request.First(); | |
if (eg.EventType == "Microsoft.EventGrid.SubscriptionValidationEvent") | |
{ | |
var data = eg.Data.ToObjectFromJson<JsonObject>(); | |
var responseData = new SubscriptionValidationResponse() | |
{ | |
ValidationResponse = data["validationCode"].ToString() | |
}; | |
return Results.Ok(responseData); | |
} | |
eg.TryCreatePushNotification(out var notification); | |
if (notification == null) | |
return Results.Ok(); | |
foreach (var refresher in refreshProvider.Refreshers) | |
{ | |
refresher.ProcessPushNotification(notification, TimeSpan.FromSeconds(1)); | |
} | |
return Results.Ok(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment