DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cesar Codes
Cesar Codes

Posted on

Using JSON and User Secrets configuration with Azure Functions

In my last post, I talked about how we can extend the FunctionsStartup class and override its Configure method to register services. In this post, I’ll share how to go about using User Secrets and JSON file configuration.

If you want to use User Secrets, you must first add the Microsoft.Extensions.Configuration.UserSecrets package from NuGet. This should also add a GUID in your project file. At this point, you can utilize User Secrets through Visual Studio or the .NET Cli as you normally would. One thing to note is that the code sample below calls the AddUserSecrets() method. If you’re not going to use user secrets, skip this step and remove the call to the method (line 16).

For utilizing a JSON file, you want to go ahead and create the JSON file and the code sample below should work.

Happy Coding,
Cesar

Top comments (1)

Collapse
 
lkurzyniec profile image
Łukasz Kurzyniec

You made User Secrets required, by sending false flag. I would make it optional by sending true flag. By this, after deploy it won't throw.

.AddUserSecrets(Assembly.GetExecutingAssembly(), true)

We want your help! Become a Tag Moderator.
Check out this survey and help us moderate our community by becoming a tag moderator here at DEV.