1 Star 3 Fork 2

james li / Cike.AutoApi

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Cike.AutoApi

介绍

🔥自动api,让你的代码更加简洁🔥。如果你的控制器层只是像以下这种,转发了业务层的代码,那么自动api将非常适合您的项目。自动api会直接根据你业务层的方法,结合restful规范动态生成控制器。

控制器只做转发,没有做任何事情,形成了大量的冗余代码

public class UserController:ControllerBase
{
    private readonly IUserAppService _userAppService;
    public UserController(IUserAppService userAppService)
    {
        _userAppService=userAppService;
    }

    [HttpGet]
    public async Task<PageResult<List<xxxDto>>> GetListAsync(xxxDto input)
    {
        return await _userAppService.GetListAsync(input);
    }
    [HttpPost]
    public async Task<xxxDto> CreateAsync(xxxDto input)
    {
        return await _userAppService.CreateAsync(input);
    }
    [HttpPost]
    public async Task<xxxDto> UpdateAsync(Guid id,xxxDto input)
    {
        return await _userAppService.UpdateAsync(id,input);
    }
}

软件架构

  • 本项目依赖于.net6

安装教程

dotnet add package Cike.AutoApi

使用说明

  • Program.cs 中添加以下两段代码
//放在AddController或者AddMvc后面
builder.Services.AddAutoApiService(opt =>
{
    //NETServiceTest所在程序集添加进动态api配置
    opt.CreateConventional(typeof(NETServiceTest).Assembly);
});
  1. 业务层代码,只需要继承 IAutoApiService 接口就行
    public class TestService : IAutoApiService
    {
        public async Task<List<string>> CreateAsync(TestCreateUpdateInput input)
        {
            return new List<string>
            {
                $"{input.Code}|{input.Name}"
            };
        }

        public async Task<string> GetListAsync(string keyword)
        {
            return keyword;
        }

        public async Task<List<string>> UpdateAsync(Guid id, TestCreateUpdateInput input)
        {
            return new List<string>
            {
                $"{id}|{input.Code}|{input.Name}"
            };
        }
        
        /// <summary>
        /// 文件流使用,上传的时候正常传到报文体内就行了
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public async Task<string> ImportAsync(IAutoApiStreamContent file)
        {
            using var fileStream = file.GetStream();


            return file.FileName;
        }
    }
  1. 最终效果

运行效果图

使用本项目的框架

  1. Yi.Framework
MIT License Copyright (c) 2023 james li Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

🔥无需创建Controller,根据restful规范 将业务层 动态生成控制器🔥 展开 收起
C# 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C#
1
https://gitee.com/fengwuyan/auto-web-api.git
git@gitee.com:fengwuyan/auto-web-api.git
fengwuyan
auto-web-api
Cike.AutoApi
develop

搜索帮助