介绍
通常在DDD开发架构中,我们写完服务层需要在控制器中写API,今天介绍一个组件 Plus.AutoApi
可以用它来动态生成 Restful 风格的 WebApi,不用写 Controller。
快速使用
在你的应用服务层中添加组件
Install-Package Plus.AutoApi
在 Startup 中注册 AutoApi
public void ConfigureServices(IServiceCollection services)
{
services.AddAutoApi(x => { });
}
AddAutoApi
同时也支持各种 Options 参数,可以自行查看。
让你的服务直接或者间接实现IAutoApi
,添加特性[AutoApi]
即可,示例代码如下:
[AutoApi]
public class WeatherService : IAutoApi
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "