Kzr*_*tof 9 c# refit asp.net-core
我正在调查改装库并评估我是否值得集成到我的项目中。
假设我有一个接受POST带有特定合同的消息的控制器:
[Route("api/[controller]")]
[ApiController]
public class KeepAliveController : ControllerBase
{
[HttpPost]
public IActionResult Post(KeepAliveContract keepAliveContract)
{
//
}
}
Run Code Online (Sandbox Code Playgroud)
根据我从refit文档中的理解,我必须创建一个界面。让我们称之为IKeepAliveService。它看起来像这样:
public interface IKeepAliveService
{
[Post("api/keepalive")]
Task SendKeepAliveAsync(KeepAliveContract keepAliveContract);
}
Run Code Online (Sandbox Code Playgroud)
这种做事方式会导致潜在的运行时错误,如果我PostAttribute在签名本身或签名中弄乱了路由。
题
有没有办法从现有控制器中自动生成这个接口,从而降低出现错误的风险?
| 归档时间: |
|
| 查看次数: |
1271 次 |
| 最近记录: |