我正在尝试使用 C# 扩展方法和 F# 中的流畅 API,但我不知道该怎么做。以下代码片段以 Asp.Net Core RC2 为例:
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
我不知道如何在 F# 中使用这样的 API。如果有人有在 F# 中使用 Fluent API 的经验,也许他们可以对此有所了解。
最佳答案
以下 C#“hello world”示例的翻译对我有用:
open System
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.AspNetCore.Http
type Startup () =
member this.Configure(app: IApplicationBuilder) =
app.Run(fun context -> context.Response.WriteAsync("Hello world!"))
[<EntryPoint>]
let main argv =
let builder = new WebHostBuilder()
let host = builder.UseKestrel().UseStartup<Startup>().Build()
host.Run()
0
关于F# 中的 C# 扩展方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37641319/