源码解析:为什么我们只写了一个app.MapGet,却生成了三个接口
1.ServiceBase
1.AutoMapRoute
源码如下:
AutoMapRoute自动创建map路由,MinimalAPI会根据service中的方法,创建对应的api接口。
比如上文的一个方法:
public async Task<WeatherForecast[]> PostWeather() {
return null;
}
MinimalAPI会帮我们生成一个Post 的Weather接口,接口地址:
http://localhost:5187/api/v1/Users/Weather
2.ParseMethod
ParseMethod方法代码:
methodName 是方法名。PostWeather方法帮我们解析方法名中的关键信息生成对应请求类型。<