控制器部分:
using Microsoft.AspNetCore.Mvc; using WebApplication1.IServices; using WebApplication1.Utility.SwaggerExt; namespace WebApplication1.Controllers { [ApiController] [Route("[controller]")] // 指定当前的控制器是哪个Swagger版本的 指定给 后台_version02 [ApiExplorerSettings(IgnoreApi = false, GroupName = nameof(ApiVersions.endApi))] public class LoginController : ControllerBase { private readonly Calc calc; public LoginController(Calc calc) { this.calc = calc; } [HttpGet] public int TestAdd(int i , int j) { return calc.Add(i, j); } } }
服务部分:
namespace WebApplication1 { public class Calc { public int Add(int i,int j) { return i + j; } } }
标签:Webapi,WebApplication1,Calc,C#,int,using,calc,public,构造函数 From: https://www.cnblogs.com/zhulongxu/p/17760377.html