阅读ASP.NET Core的文档,有两种方法可以选择Startup:Configure和ConfigureServices.
这些似乎都不是放置我想在启动时运行的自定义代码的好地方.也许我想在我的数据库中添加自定义字段(如果它不存在),检查特定文件,将一些数据播种到我的数据库中等等.我想运行一次的代码,只是在应用程序启动时.
是否有一个首选/推荐的方法来实现这一目标?
我正在玩F#中使用SqlClient而且我在使用时遇到了困难SqlDataReader.ReadAsync.我正在尝试做F#等价的
while (await reader.ReadAsync) { ... }
在F#中做到这一点的最佳方法是什么?以下是我的完整计划.它有效,但我想知道是否有更好的方法来做到这一点.
open System
open System.Data.SqlClient
open System.Threading.Tasks
let connectionString = "Server=.;Integrated Security=SSPI"
module Async =
let AwaitVoidTask : (Task -> Async<unit>) =
Async.AwaitIAsyncResult >> Async.Ignore
// QUESTION: Is this idiomatic F#? Is there a more generally-used way of doing this?
let rec While (predicateFn : unit -> Async<bool>) (action : unit -> unit) : Async<unit> =
async {
let! b = predicateFn()
match b with
| true -> action(); do! While …Run Code Online (Sandbox Code Playgroud)