Skip to content

Commit a8651a7

Browse files
committed
Add user secrets pimbrouwers#115
1 parent ccc4307 commit a8651a7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Falco/ConfigBuilder.fs

+13-2
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@ type ConfigFile =
88
| XmlFile of path : string
99
| JsonFile of path : string
1010

11+
1112
type ConfigBuilderSpec =
1213
{ AddEnvVars : bool
1314
BasePath : string
1415
RequiredFiles : ConfigFile list
1516
OptionalFiles : ConfigFile list
16-
InMemory : Map<string, string> }
17+
InMemory : Map<string, string>
18+
AddUserSecrets: bool}
1719

1820
static member Empty =
1921
{ AddEnvVars = false
2022
BasePath = Directory.GetCurrentDirectory()
2123
RequiredFiles = []
2224
OptionalFiles = []
23-
InMemory = Map.empty }
25+
InMemory = Map.empty
26+
AddUserSecrets= false }
2427

2528
/// Computation expression to allow for elegant IConfiguration construction.
2629
type ConfigBuilder (args : string[]) =
@@ -51,6 +54,9 @@ type ConfigBuilder (args : string[]) =
5154

5255
bldr.AddCommandLine(args) |> ignore
5356

57+
if conf.AddUserSecrets then
58+
bldr.AddUserSecrets() |> ignore
59+
5460
bldr.Build() :> IConfiguration
5561

5662
/// Sets the base path of the ConfigurationBuilder.
@@ -101,6 +107,11 @@ type ConfigBuilder (args : string[]) =
101107
member _.AddOptionalJsonFile (conf : ConfigBuilderSpec, filePath : string) =
102108
{ conf with OptionalFiles = (JsonFile filePath) :: conf.OptionalFiles }
103109

110+
///Adds optional user secrets to the ConfigurationBuilder.
111+
[<CustomOperation("optional_user_secrets")>]
112+
member _.AddOptionalUserSecrets (conf : ConfigBuilderSpec) =
113+
{ conf with AddUserSecrets = true }
114+
104115
[<AutoOpen>]
105116
module ConfigurationBuilder =
106117
/// Computation expression to allow for elegant IConfiguration construction.

0 commit comments

Comments
 (0)