我已经开始学习函数式编程,虽然在正常情况下链接方法看起来很棒(在我看来),但在处理 async/await 时它真的变得很难看
await (await (await CosmosDbRepository<ApplicationProcess>
.GetItemAsync(param.ProcessId))
.Historize(() => _analyseFinanciereService.ProcessAsync(),
ProcessStepEnum.Application))
.Notify(p => p.GetLastStep());
Run Code Online (Sandbox Code Playgroud)
有什么办法可以消除这种噪音吗?
编辑 :
public static async Task<ApplicationProcess> Historize(
this ApplicationProcess process,
Func<Task> fn,
ProcessStepEnum stepEnum)
{
var dateStart = DateTime.UtcNow;
var error = string.Empty;
try
{
await fn();
return process;
}
…
public static async Task Notify<TResult>(
this ApplicationProcess process,
Func<ApplicationProcess, TResult> fn)
...
Run Code Online (Sandbox Code Playgroud)
Edit2:使用扩展方法接受任务
await CosmosDbRepository<ApplicationProcess>
.GetItemAsync(param.ProcessId)
.HistorizeAsync(() => _analyseFinanciereService.ProcessAsync(), ProcessStepEnum.Application)
.NotifyAsync(p => p.GetLastStep());
Run Code Online (Sandbox Code Playgroud)
所以这就是我一直在寻找的,即使我对最新的评论感到困惑
我有这个查询,我找不到正确的方法来获得价格(.Amount.GetValueOrDefault()).
private IEnumerable<Product> GetSubsciptionOffers(IEnumerable<StripeProduct> productList)
{
return productList
.Select(async product => new Product
{
Name = product.Name,
Id = product.Id,
Image = new Uri(product.Images.First()),
Description = product.Description,
OfferType = OfferTypeEnum.Pro,
Price = await _planRepo.GetPlanByIdAsync(product.Metadata.First().Value).Amount.GetValueOrDefault()
});
}
Run Code Online (Sandbox Code Playgroud)
错误是:
任务不包含金额的定义
在我的 asp.net core 2.1 api 中,我添加了静态文件服务和 Swashbuckle,但显然找不到生成的 .json
services.AddSwaggerGen(x =>
x.SwaggerDoc("Swagger", new Info { Title = "Asp.Net Core 2 Api", Description = "Swagger Core Api" }));
----
app.UseCors("AllowAll");
app.UseAuthentication();
app.UseStaticFiles();
app.UseSwagger();
app.UseSwaggerUI(x => x.SwaggerEndpoint("/swagger/swagger.json", "Core Api"));
Run Code Online (Sandbox Code Playgroud)
任何的想法?谢谢