forked from Azure/AppConfiguration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowMessage.cs
44 lines (38 loc) · 1.73 KB
/
ShowMessage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
using Microsoft.Extensions.Logging;
namespace FunctionApp
{
public class ShowMessage
{
private readonly IConfiguration _configuration;
private readonly IConfigurationRefresher _configurationRefresher;
public ShowMessage(IConfiguration configuration, IConfigurationRefresherProvider refresherProvider)
{
_configuration = configuration;
_configurationRefresher = refresherProvider.Refreshers.First();
}
[FunctionName("ShowMessage")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
// Signal to refresh the configuration if the registered key(s) is modified.
// This will be a no-op if the cache expiration time window is not reached.
// The configuration is refreshed asynchronously without blocking the execution of the current function.
_ = _configurationRefresher.TryRefreshAsync();
string key = "TestApp:Settings:Message";
string message = _configuration[key];
return message != null
? (ActionResult)new OkObjectResult(message)
: new BadRequestObjectResult($"Please create a key-value with the key '{key}' in Azure App Configuration.");
}
}
}