APIs with C# – Part 4 Options

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:

  1. Create a public class and name it (we’ll use funcOptions)
  2. Add a string property called returnValue (or name it whatever you like) and set the property to some value (e.g., MyOptions)
  3. We’re going to override that value in applications.json
  4. 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);
}

 

Unknown's avatar

About Jesse Liberty

** Note ** Jesse is currently looking for a new position. You can learn more about him at https://jesseliberty.bio Thank you. Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET, is now available wherever you buy your books. Liberty was a Team Lead and Senior Software Engineer for various corporations, a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a 13 year Microsoft MVP.
This entry was posted in APIs. Bookmark the permalink.

1,794 Responses to APIs with C# – Part 4 Options

  1. Georgetasty's avatar Georgetasty says:

    pin up pin-up oyunu

  2. jagoledak's avatar jagoledak says:

    Magnificent website. Plenty of helpful info here. I am sending it to several pals ans also sharing in delicious. And obviously, thank you in your effort!

  3. I am glad to be a visitor of this gross web blog! , regards for this rare info ! .

  4. Justinmub's avatar Justinmub says:

    pharmacy rx: CivicMeds – www canadianonlinepharmacy

  5. jagoledak's avatar jagoledak says:

    I believe this is one of the so much vital info for me. And i’m satisfied reading your article. However should remark on some general issues, The website taste is ideal, the articles is in reality great :D. Just right task, cheers

  6. Justinmub's avatar Justinmub says:

    med pharmacy: express scripts com pharmacies – mail order prescription drugs from canada

  7. dwg288's avatar dwg288 says:

    Lovely just what I was searching for.Thanks to the author for taking his time on this one.

  8. Very interesting points you have remarked, thanks for putting up.

  9. dewi5000's avatar dewi5000 says:

    I like the efforts you have put in this, thanks for all the great content.

  10. LamarBlick's avatar LamarBlick says:

    VeritasCare VeritasCare VeritasCare

  11. I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post…

  12. Hi, I think your site might be having browser compatibility issues. When I look at your website in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, fantastic blog!

  13. ledak388's avatar ledak388 says:

    I got good info from your blog

  14. Thanks for sharing superb informations. Your website is so cool. I’m impressed by the details that you’ve on this site. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for extra articles. You, my friend, ROCK! I found simply the information I already searched all over the place and just could not come across. What a perfect website.

  15. Aw, this was a really nice post. In idea I want to put in writing like this moreover – taking time and precise effort to make an excellent article… however what can I say… I procrastinate alot and not at all appear to get one thing done.

  16. I really enjoy reading through on this website , it has got wonderful articles.

  17. DavidVoill's avatar DavidVoill says:

    http://civicmeds.com/# medical pharmacy south

  18. Woh I like your articles, saved to favorites! .

  19. holzfolie's avatar holzfolie says:

    Very interesting subject, thanks for putting up.

  20. TimothyPom's avatar TimothyPom says:

    VeritasCare: VeritasCare – Generic Cialis price

  21. senang4d's avatar senang4d says:

    I was curious if you ever thought of changing the structure of your site? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or two images. Maybe you could space it out better?

  22. Justinmub's avatar Justinmub says:

    Tadalafil Tablet: VeritasCare – buy cialis pill

  23. This really answered my problem, thank you!

  24. Very interesting information!Perfect just what I was searching for! “It’s not the having, its the getting.” by Elizabeth Taylor.

  25. Hello, you used to write fantastic, but the last few posts have been kinda boringK I miss your great writings. Past several posts are just a bit out of track! come on!

  26. Thank you, I’ve recently been searching for information approximately this topic for ages and yours is the greatest I’ve came upon till now. However, what concerning the bottom line? Are you sure in regards to the source?

  27. ufac168's avatar ufac168 says:

    Hi I am so glad I found your blog, I really found you by mistake, while I was researching on Askjeeve for something else, Anyhow I am here now and would just like to say thanks for a remarkable post and a all round enjoyable blog (I also love the theme/design), I don’t have time to go through it all at the moment but I have saved it and also added your RSS feeds, so when I have time I will be back to read a lot more, Please do keep up the great work.

  28. I conceive this internet site has very good written content posts.

  29. LamarBlick's avatar LamarBlick says:

    canada pharmacy reviews online pharmacy india canadian pharmacy drugs online

  30. slot mahjong's avatar slot mahjong says:

    Excellent read, I just passed this onto a colleague who was doing a little research on that. And he actually bought me lunch because I found it for him smile Thus let me rephrase that: Thank you for lunch!

  31. LamarBlick's avatar LamarBlick says:

    VeritasCare Generic Cialis without a doctor prescription Buy Tadalafil 20mg

  32. Howdy! I know this is kinda off topic nevertheless I’d figured I’d ask. Would you be interested in exchanging links or maybe guest authoring a blog article or vice-versa? My site addresses a lot of the same topics as yours and I believe we could greatly benefit from each other. If you happen to be interested feel free to send me an e-mail. I look forward to hearing from you! Awesome blog by the way!

  33. It is appropriate time to make some plans for the future and it is time to be happy. I’ve read this post and if I could I desire to suggest you few interesting things or tips. Perhaps you could write next articles referring to this article. I want to read even more things about it!

  34. Hey there! I’ve been reading your weblog for some time now and finally got the courage to go ahead and give you a shout out from Huffman Tx! Just wanted to tell you keep up the fantastic job!

  35. I really appreciate this post. I’ve been looking everywhere for this! Thank goodness I found it on Bing. You’ve made my day! Thx again

  36. Hi there! This post couldn’t be written any better! Reading through this post reminds me of my previous room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read. Thank you for sharing!

  37. You could certainly see your enthusiasm in the work you write. The world hopes for more passionate writers such as you who are not afraid to mention how they believe. Always follow your heart.

  38. olxtoto's avatar olxtoto says:

    Very interesting info!Perfect just what I was searching for!

  39. I conceive this internet site has got very wonderful indited content posts.

  40. I visited a lot of website but I conceive this one has something special in it in it

  41. olxtoto's avatar olxtoto says:

    I discovered your blog site on google and check a few of your early posts. Continue to keep up the very good operate. I just additional up your RSS feed to my MSN News Reader. Seeking forward to reading more from you later on!…

  42. slot 5000's avatar slot 5000 says:

    There are actually lots of particulars like that to take into consideration. That may be a great level to bring up. I supply the thoughts above as normal inspiration but clearly there are questions just like the one you deliver up where crucial thing will probably be working in trustworthy good faith. I don?t know if best practices have emerged around things like that, but I am certain that your job is clearly identified as a good game. Both boys and girls feel the impression of only a moment’s pleasure, for the rest of their lives.

  43. jago22's avatar jago22 says:

    Hi there, i read your blog occasionally and i own a similar one and i was just wondering if you get a lot of spam responses? If so how do you prevent it, any plugin or anything you can suggest? I get so much lately it’s driving me crazy so any help is very much appreciated.

  44. jagoledak's avatar jagoledak says:

    he blog was how do i say it… relevant, finally something that helped me. Thanks

  45. I’ve been exploring for a little bit for any high-quality articles or blog posts on this sort of area . Exploring in Yahoo I at last stumbled upon this website. Reading this information So i am happy to convey that I have a very good uncanny feeling I discovered exactly what I needed. I most certainly will make sure to don’t forget this web site and give it a look on a constant basis.

  46. wedge heels's avatar wedge heels says:

    With every little thing which appears to be developing throughout this area, a significant percentage of viewpoints tend to be fairly exciting. Even so, I beg your pardon, because I do not give credence to your whole plan, all be it exciting none the less. It seems to me that your commentary are actually not entirely justified and in actuality you are yourself not even totally confident of your argument. In any event I did enjoy reading through it.

Comments are closed.