小编Jar*_*ore的帖子

ASP.NET Core中的应用程序启动代码

阅读ASP.NET Core文档,有两种方法可以选择Startup:Configure和ConfigureServices.

这些似乎都不是放置我想在启动时运行的自定义代码的好地方.也许我想在我的数据库中添加自定义字段(如果它不存在),检查特定文件,将一些数据播种到我的数据库中等等.我想运行一次的代码,只是在应用程序启动时.

是否有一个首选/推荐的方法来实现这一目标?

c# startup asp.net-core

31
推荐指数
3
解决办法
9923
查看次数

'while'在异步计算表达式中,条件是异步的

我正在玩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)

f# asynchronous sqldatareader sqlclient

10
推荐指数
1
解决办法
572
查看次数

标签 统计

asp.net-core ×1

asynchronous ×1

c# ×1

f# ×1

sqlclient ×1

sqldatareader ×1

startup ×1