How do I handle async operations in Startup.Configure?

后端 未结 4 527
暗喜
暗喜 2021-02-01 11:57

In my ASP.NET 5 app, I want to load some data from Azure into a cache inside my Startup.Configure method. The Azure SDK exposes async methods exclusively. Typically, calling an

4条回答
  •  一个人的身影
    2021-02-01 12:15

    You can do some asynchronous work, but the method is synchronous and you cannot change that. This means you need synchronously wait for async calls to be completed.

    You don't want to return from a Startup method if the startup is not finished yet, right? Your solution seems to be all right.

    As for exception handling: If there's a piece of work that your application can't run properly without, you should let the Startup method fail (see Fail-fast). If it isn't something critical I would enclose the relevant part in a try catch block and just log the problem for later inspection.

提交回复
热议问题