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. dewi11's avatar dewi11 says:

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

  2. dewi11's avatar dewi11 says:

    As I website possessor I conceive the subject material here is rattling good, regards for your efforts.

  3. kilat333's avatar kilat333 says:

    Thank you for sharing superb informations. Your site is so cool. I am impressed by the details that you have on this web site. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for more articles. You, my pal, ROCK! I found just the information I already searched everywhere and just could not come across. What a perfect web site.

  4. Whats up! I simply wish to give a huge thumbs up for the good information you’ve got right here on this post. I might be coming back to your weblog for more soon.

  5. togel 4d's avatar togel 4d says:

    I’d must check with you here. Which isn’t something I often do! I get pleasure from reading a post that can make individuals think. Additionally, thanks for allowing me to comment!

  6. You have noted very interesting points! ps decent site. “We simply rob ourselves when we make presents to the dead.” by Publilius Syrus.

  7. Thank you for sharing excellent informations. Your site is so cool. I am impressed by the details that you’ve on this blog. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for extra articles. You, my pal, ROCK! I found just the information I already searched all over the place and just couldn’t come across. What an ideal web site.

  8. dewi11's avatar dewi11 says:

    Way cool, some valid points! I appreciate you making this article available, the rest of the site is also high quality. Have a fun.

  9. I view something genuinely interesting about your website so I saved to my bookmarks.

  10. dewi11's avatar dewi11 says:

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

  11. dwg288's avatar dwg288 says:

    I am continually invstigating online for ideas that can help me. Thanks!

  12. dwg288's avatar dwg288 says:

    I’m so happy to read this. This is the kind of manual that needs to be given and not the random misinformation that is at the other blogs. Appreciate your sharing this greatest doc.

  13. I am no longer certain where you are getting your information, but good topic. I needs to spend a while finding out much more or understanding more. Thanks for fantastic information I used to be on the lookout for this info for my mission.

  14. Hello, Neat post. There is a problem together with your website in internet explorer, would test this?K IE still is the marketplace chief and a big component to other people will leave out your fantastic writing due to this problem.

  15. monas77's avatar monas77 says:

    I am not sure where you’re getting your info, but good topic. I needs to spend some time learning more or understanding more. Thanks for magnificent info I was looking for this info for my mission.

  16. Have you ever considered about including a little bit more than just your articles? I mean, what you say is important and everything. However imagine if you added some great pictures or videos to give your posts more, “pop”! Your content is excellent but with images and video clips, this blog could undeniably be one of the best in its niche. Awesome blog!

  17. obviously like your web-site but you need to check the spelling on several of your posts. Several of them are rife with spelling problems and I find it very troublesome to tell the truth nevertheless I will certainly come back again.

  18. Spot on with this write-up, I actually suppose this web site needs far more consideration. I’ll probably be again to read far more, thanks for that info.

  19. A lot of the things you assert happens to be astonishingly precise and it makes me wonder why I hadn’t looked at this in this light before. This particular article truly did turn the light on for me as far as this subject matter goes. However there is actually just one factor I am not really too comfortable with so whilst I try to reconcile that with the main theme of your issue, allow me see exactly what the rest of the visitors have to point out.Very well done.

  20. Edgarpaype's avatar Edgarpaype says:

    semaglutide weight loss dosage chart: rybelsus bioavailability – buy online medicine

  21. ledak388's avatar ledak388 says:

    I real happy to find this site on bing, just what I was looking for : D too saved to fav.

  22. dewihoki's avatar dewihoki says:

    Hello! Do you use Twitter? I’d like to follow you if that would be okay. I’m undoubtedly enjoying your blog and look forward to new updates.

  23. dewi188's avatar dewi188 says:

    Thanks for sharing superb informations. Your website is very cool. I’m impressed by the details that you’ve on this site. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for more articles. You, my pal, ROCK! I found just the info I already searched all over the place and just could not come across. What a great web-site.

  24. dewi11's avatar dewi11 says:

    Hi, i feel that i noticed you visited my weblog thus i got here to “return the choose”.I’m attempting to in finding issues to improve my website!I suppose its adequate to make use of a few of your concepts!!

  25. dewi188's avatar dewi188 says:

    I’ll right away seize your rss as I can not find your email subscription link or e-newsletter service. Do you’ve any? Kindly permit me understand so that I could subscribe. Thanks.

  26. dewi11's avatar dewi11 says:

    There are some fascinating cut-off dates on this article however I don’t know if I see all of them middle to heart. There may be some validity however I will take hold opinion until I look into it further. Good article , thanks and we would like extra! Added to FeedBurner as properly

  27. prasannam's avatar prasannam says:

    Hello there! This is kind of off topic but I need some advice from an established blog. Is it tough to set up your own blog? I’m not very techincal but I can figure things out pretty fast. I’m thinking about creating my own but I’m not sure where to begin. Do you have any ideas or suggestions? Appreciate it

  28. ledak388's avatar ledak388 says:

    Yeah bookmaking this wasn’t a risky decision outstanding post! .

  29. ultra33's avatar ultra33 says:

    I have been absent for a while, but now I remember why I used to love this web site. Thank you, I’ll try and check back more often. How frequently you update your website?

  30. Edgarpaype's avatar Edgarpaype says:

    ozempic semaglutide: semaglutide life – new pharmacy online

  31. senang4d's avatar senang4d says:

    I like the efforts you have put in this, appreciate it for all the great posts.

  32. ledak288's avatar ledak288 says:

    I would like to thnkx for the efforts you have put in writing this blog. I am hoping the same high-grade blog post from you in the upcoming as well. In fact your creative writing abilities has inspired me to get my own blog now. Really the blogging is spreading its wings quickly. Your write up is a good example of it.

  33. Pretty! This was a really wonderful post. Thank you for your provided information.

  34. poros77's avatar poros77 says:

    I as well as my guys have been reading through the excellent suggestions from your site while then developed an awful feeling I never expressed respect to the web site owner for those secrets. These people are actually absolutely excited to see them and have now honestly been using these things. Many thanks for truly being quite accommodating and for making a decision on this kind of helpful issues most people are really desperate to be aware of. My sincere apologies for not saying thanks to you earlier.

  35. ultra33's avatar ultra33 says:

    But a smiling visitant here to share the love (:, btw outstanding design. “Treat the other man’s faith gently it is all he has to believe with.” by Athenus.

  36. Davidten's avatar Davidten says:

    over the counter antibiotics generic antibiotics online pharmacy best online doctor for antibiotics

  37. Really wonderful information can be found on site.

  38. gopay303's avatar gopay303 says:

    Hello. excellent job. I did not anticipate this. This is a great story. Thanks!

  39. Davidten's avatar Davidten says:

    rybelsus 7 mg side effects where can i get semaglutide near me rybelsus novo nordisk

  40. Edgarpaype's avatar Edgarpaype says:

    semaglutide compounded near me: semaglutide life – online pharmacy no prescription

  41. senangslot's avatar senangslot says:

    I’ve recently started a blog, the info you offer on this website has helped me greatly. Thank you for all of your time & work.

  42. poros77's avatar poros77 says:

    Simply want to say your article is as astonishing. The clarity in your put up is simply spectacular and i could suppose you’re a professional on this subject. Well along with your permission let me to seize your feed to stay up to date with imminent post. Thanks a million and please continue the rewarding work.

  43. Edgarpaype's avatar Edgarpaype says:

    over the counter antibiotics: antibiotics cheap – antibiotics cheap

  44. Danielgek's avatar Danielgek says:

    https://semaglutide.life/# how much weight can you lose on semaglutide

  45. very nice publish, i definitely love this website, carry on it

  46. poros77's avatar poros77 says:

    Its like you learn my thoughts! You seem to grasp a lot about this, like you wrote the guide in it or something. I think that you could do with some to drive the message home a little bit, but other than that, this is fantastic blog. An excellent read. I’ll certainly be back.

  47. gopay303's avatar gopay303 says:

    I have been browsing online more than three hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. Personally, if all webmasters and bloggers made good content as you did, the internet will be a lot more useful than ever before.

  48. You got a very great website, Gladiolus I observed it through yahoo.

  49. gopay303's avatar gopay303 says:

    The very core of your writing while appearing reasonable originally, did not sit very well with me after some time. Somewhere within the sentences you actually managed to make me a believer unfortunately just for a while. I however have a problem with your jumps in assumptions and one would do nicely to help fill in those gaps. In the event that you actually can accomplish that, I could certainly be impressed.

Comments are closed.