如何在configureServices中访问配置

时间:2018-06-12 06:54:59

标签: f# f#-giraffe

如何从Giraffe-FSharp中的configureServices方法内部访问配置?

以下是SAFE template通过dotnet new SAFE -lang F# --server giraffe创建的长颈鹿设置的简略部分:

let configureServices (services : IServiceCollection) =
    services.AddCors()                  |> ignore
    services.AddGiraffe()               |> ignore
    // Want to access configuration here.



[<EntryPoint>]
let main _ =
    let contentRoot = Directory.GetCurrentDirectory()
    let webRoot     = Path.Combine(contentRoot, "WebRoot")

    WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(contentRoot)
        .UseIISIntegration()
        .UseWebRoot(webRoot)
        .Configure(Action<IApplicationBuilder> configureApp)
        .ConfigureAppConfiguration(Action<WebHostBuilderContext, IConfigurationBuilder> configureAppConfig)
        .ConfigureServices(configureServices)
        .ConfigureLogging(configureLogging)
        .Build()
        .Run()
    0

1 个答案:

答案 0 :(得分:2)

从服务集合中获取服务提供者,然后使用它来获取配置:

Access-Control-Allow-Methods