Giraffe: Where Configuration coming from in the SampleApp?

Created on 18 Apr 2018  路  4Comments  路  Source: giraffe-fsharp/Giraffe

In the sample https://github.com/giraffe-fsharp/Giraffe/blob/master/samples/SampleApp/SampleApp/Program.fs

f# let configuredHandler = fun (next : HttpFunc) (ctx : HttpContext) -> let configuration = ctx.GetService<IConfiguration>() text configuration.["HelloMessage"] next ctx

Where is "HelloMessage" supposed to be coming from?

I'm trying to figure out how to read values from appsettings.json and appsettings.Development.json and I came across this example which had intention of reading from some type of configuration file I think? However there is no configuration file in that folder.

question

Most helpful comment

If no configuration provider (like AddJsonFile/AddXmlFile) service is specifed (like in the sample app). Asp.Net will automatically setup a couple of default providers like MemoryConfigurationProvider, EnvironmentVariablesProvider, and JsonProvider.

So you can simply drop in a appsettings.json file and it will be picked up.
Or you can add an environment variable and it will be picked up.
Or you can set up your own configuration like any other asp.net project.

Buy be wary of the current working directory when starting the sample, it changes where the system will look for the configuration (aka drop the appsettings.json in giraffe root folder, next to the README file, if starting from vs code).

All 4 comments

If no configuration provider (like AddJsonFile/AddXmlFile) service is specifed (like in the sample app). Asp.Net will automatically setup a couple of default providers like MemoryConfigurationProvider, EnvironmentVariablesProvider, and JsonProvider.

So you can simply drop in a appsettings.json file and it will be picked up.
Or you can add an environment variable and it will be picked up.
Or you can set up your own configuration like any other asp.net project.

Buy be wary of the current working directory when starting the sample, it changes where the system will look for the configuration (aka drop the appsettings.json in giraffe root folder, next to the README file, if starting from vs code).

What @lukethenuke said is correct. There's also a nice blog post which explains you step by step how to use an appsettings.json file in Giraffe.

@dustinmoris hey, came across this issue, seems like the link in your last comment is dead. Do you know by any chance if the blog post moved somewhere?

Cheers

Is the link still dead for you? I just checked and it loads fine for me, however, I've created an archive.is link in case it disappears again:
https://archive.is/MsrsE

Was this page helpful?
0 / 5 - 0 ratings