我有一个API,负责在数据库中插入短信详细信息。它通过对存储库进行同步调用来实现,我认为可以异步实现该存储库,我该如何实现呢?还是最好的方式来处理这种情况。代码片段示例受到高度赞赏,因为我仍在继续围绕.NET进行包装。api:public IHttpActionResult SendSMSNotification([FromBody] SMSNotification smsNotification) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _service.SendSMS(smsNotification); return Ok(); }服务:internal void SendSMS(SMSNotification smsNotification) { _repository.Notify(_mapperService.GetSMSNotification(smsNotification)); }映射器:public SMSNotification GetSMSNotification(SMSNotification message) { return AutoMapper.Mapper.Map<SMSNotification>(message); }回购:public virtual bool Notify(SMSNotification request) { using (var sql = _sqlMapper.CreateCommand('Database', 'Stored proc')) { sql.AddParam("@fMessage", request.Message); //.............. //.............. more params var retvalParamOutput = sql.AddOutputParam("@fRetVal", System.Data.SqlDbType.Int); sql.Execute(); return retvalParamOutput.GetSafeValue<int>() == 1; } }sql这里是一个自定义的东西,它具有以下方法: public static int Execute(this IDataCommand @this); [AsyncStateMachine(typeof(<ExecuteAsync>d__1))] public static Task<int> ExecuteAsync(this IDataCommand @this);
1 回答
- 1 回答
- 0 关注
- 139 浏览
添加回答
举报
0/150
提交
取消