@@ -8,19 +8,22 @@ type ConfigFile =
8
8
| XmlFile of path : string
9
9
| JsonFile of path : string
10
10
11
+
11
12
type ConfigBuilderSpec =
12
13
{ AddEnvVars : bool
13
14
BasePath : string
14
15
RequiredFiles : ConfigFile list
15
16
OptionalFiles : ConfigFile list
16
- InMemory : Map < string , string > }
17
+ InMemory : Map < string , string >
18
+ AddUserSecrets: bool }
17
19
18
20
static member Empty =
19
21
{ AddEnvVars = false
20
22
BasePath = Directory.GetCurrentDirectory()
21
23
RequiredFiles = []
22
24
OptionalFiles = []
23
- InMemory = Map.empty }
25
+ InMemory = Map.empty
26
+ AddUserSecrets= false }
24
27
25
28
/// Computation expression to allow for elegant IConfiguration construction.
26
29
type ConfigBuilder ( args : string []) =
@@ -51,6 +54,9 @@ type ConfigBuilder (args : string[]) =
51
54
52
55
bldr.AddCommandLine( args) |> ignore
53
56
57
+ if conf.AddUserSecrets then
58
+ bldr.AddUserSecrets() |> ignore
59
+
54
60
bldr.Build() :> IConfiguration
55
61
56
62
/// Sets the base path of the ConfigurationBuilder.
@@ -101,6 +107,11 @@ type ConfigBuilder (args : string[]) =
101
107
member _.AddOptionalJsonFile ( conf : ConfigBuilderSpec , filePath : string ) =
102
108
{ conf with OptionalFiles = ( JsonFile filePath) :: conf.OptionalFiles }
103
109
110
+ ///Adds optional user secrets to the ConfigurationBuilder.
111
+ [<CustomOperation( " optional_user_secrets" ) >]
112
+ member _.AddOptionalUserSecrets ( conf : ConfigBuilderSpec ) =
113
+ { conf with AddUserSecrets = true }
114
+
104
115
[<AutoOpen>]
105
116
module ConfigurationBuilder =
106
117
/// Computation expression to allow for elegant IConfiguration construction.
0 commit comments