NET provides support for passing options via environment variables, appsettings.json, and XML files. as well as command line arguments. In short, each higher level overrides the settings in lower levels.
To add options:
- Create a public class and name it (we’ll use funcOptions)
- Add a string property called returnValue (or name it whatever you like) and set the property to some value (e.g., MyOptions)
- We’re going to override that value in applications.json
- Add a property in appsettings.json (e.g., retVal) and set that property to a different value than we did in step 2
It’s time to set up the startup configuration. When you are done, your Program.cs should look like this:
var host = new HostBuilder() .ConfigureFunctionsWebApplication() .ConfigureServices((context, services) => { services.AddApplicationInsightsTelemetryWorkerService() .ConfigureFunctionsApplicationInsights() .AddOptions<MyOptions> .BindConfiguration(""); }) .Build(); host.Run();
The next step is to inject IOptions<MyOptions> and in the constructor set a member variable.
The Run method will look like this:
[Function("Function1")] public IActionResult Run(HttpTrigger(AuthorizationLevel .Anonymous, "get", "post")] HttpRequest req) { return new OKObjectResult(options.value.retValue); }
I was looking through some of your articles on this internet site and I think this internet site is very instructive! Continue putting up.
I haven’t checked in here for some time as I thought it was getting boring, but the last few posts are good quality so I guess I’ll add you back to my daily bloglist. You deserve it my friend 🙂
You are my inspiration , I possess few blogs and infrequently run out from to post : (.