1

A bare bone implementation for retrieving user secrets using F#



I am new to f# (coming from c#) and I was looking to retrieve user secrets for a bare bone CLI project. I did not want to import ApplicationBuilder or ServiceCollection since I did not need to create something more complex (like an API or web app) which relies on several dependencies.
I wanted to use IConfigurationRoot which only requires 'Microsoft.Extensions.Configuration.UserSecrets'. Initially I had some trouble implementing it but I finally found it.

1 Answer 1

2
  1. install the aforementioned nuget package

  2. Create the builder:

    type Program = class end
    
    [<EntryPoint>]
    let main _ =
        let config =
            ConfigurationBuilder()
                .AddUserSecrets<Program>() 
                .Build()
    
        // config["secrets:your-secret"] 
        0
    

Why do you need a Program class? Shoud we not write idiomatic F#?

F# CLI apps typically just use modules and keep it clean and functional. But AddUserSecrets() expects a class or a type.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.