Virtuesoft.Framework.Gateaway 7.0.9

dotnet add package Virtuesoft.Framework.Gateaway --version 7.0.9                
NuGet\Install-Package Virtuesoft.Framework.Gateaway -Version 7.0.9                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Virtuesoft.Framework.Gateaway" Version="7.0.9" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Virtuesoft.Framework.Gateaway --version 7.0.9                
#r "nuget: Virtuesoft.Framework.Gateaway, 7.0.9"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Virtuesoft.Framework.Gateaway as a Cake Addin
#addin nuget:?package=Virtuesoft.Framework.Gateaway&version=7.0.9

// Install Virtuesoft.Framework.Gateaway as a Cake Tool
#tool nuget:?package=Virtuesoft.Framework.Gateaway&version=7.0.9                

Virtuesoft.Framework.Gateaway

高性能,轻量级,简单的接口框架,升级到.NET6

简介

自2018年来一直在使用与更新迭代,一切为了简单,为了简单的一切.
只是为了做个短小精干的接口服务,去除臃肿.该框架在生产环境中表现良好,
扩展性强,性能优越,特别是其足够的简单!
用于接口快速开发,扩展签名验证,IP限制,格式化参数,访问记录等等.
给外包部门使用广受好评,曾经为客户撑起上亿/日的交易成绩,
顶住了大几十万的访问并发.

安装使用

Install-Package Virtuesoft.Framework.Gateaway -Version 6.0.1

Program.cs 简单使用

using Virtuesoft.Framework.Gateaway;

var builder = WebApplication.CreateBuilder(args);
var sqlConnectionString = builder.Configuration.GetConnectionString("DbContext");
builder
    .Logging
    .AddConsole()
    .Services
    //配置EF
    .AddDbContextPool<DataContext>(option =>
    {
        option.UseSqlServer(sqlConnectionString);
    })
    .AddGateaway();
var app = builder.Build();
//使用接口
app.UseGateaway();
app.Run("http://*:5000");

编写接口

public class User:GateawayBase
{
    ILogger<User> Logger { get; }
    DataContext Db { get; }
    public User(DataContext context,ILogger<User> logger)
    {
        Logger=logger;
        Db = context;
    }
    public async Task<object> Add()
    {
        try
        {
            var result= await Db.Accounts.AddAsync(new MemberAccount()
            {
                Name = $"N{new Random((int)DateTime.Now.Ticks).Next(1111, 9999)}",
                Role = Db.Roles.FirstOrDefault()
            });
            await Db.SaveChangesAsync();
            return Success(new {
                result.Entity.ID,
                result.Entity.No,
                result.Entity.Name,
                result.Entity.Phone,
                result.Entity.CreateTime
            });
        }
        catch (Exception ex)
        {
            Logger.LogError(ex, $"Add:{ex.Message}");
            throw;
        }
    }
    public object Get()
    {
        var result = Db.Accounts
            .OrderByDescending(t => t.No)
            .Select(t => new
            {
                t.ID,
                t.Name,
                t.Phone,
                t.Age,
                t.No,
                t.Status,
                Role = new
                {
                    t.Role.ID,
                    t.Role.Name
                }
            })
            .FirstOrDefault();
        return Success(result);
    }
     public dynamic Detail(string id){
     var t = Db.Accounts.Include(t=>t.Role).FirstOrDefault(t=>t.ID==id);
        return new
        {
            t.ID,
            t.Name,
            t.Phone,
            t.Age,
            t.No,
            t.Status,
            Role = new
            {
                t.Role.ID,
                t.Role.Name
            }
        };
     }
}

访问

默认文档地址
GET:http://localhost:5000/api/doc
POST: JSON {"method":"api.doc"}

POST / HTTP/1.1
Host: localhost:5000
Content-Type: application/json
User-Agent: App/1.0

{
	"method":"user.detail",
    "id":1000
}

GET / HTTP/1.1 http://localhost:5000/user/detail?id=10000

数据返回

//弱类型返回
public object Get(){
    //自定义其他重载
    return Success();//默认执行成功,不返回任何数据
    return Success(new {name="孙悟空"});//带数据返回
    return Error();
    return Error("账户名密码错误");
}
//强类型返回
public Account Get(){
    return new Account(){Name="孙悟空"};
}

默认格式

{
    "s": true,//执行状态
    "c": 200, //执行代码 授权失败:401,其他代码可以自定义
    "m": "ok",//执行消息
    //返回数据
    "d": {
        "ID": "99ead98b666549b590a529f453336e41",
        "No": 7364,
        "Name": "N9189",
        "Phone": "+861642609352",
        "CreateTime": "2022-01-20T00:22:32.5188842+08:00"
    }
}

路由与参数

路由参数:均小写,
参数支持:json,from,path
方法支持:POST,GET

//默认路由 user.*
public class User:GateawayBase
{
    //默认路由 user.get
    public object Get(string id){
        ...
    }
}
//自定义路由
[Gateaway(Name ="account",Display ="用户接口")]
public class User:GateawayBase{
    //完整路由: account.detail.get
    [Gateaway(Name ="detail.get",Display ="获取用户")]
    public object Get(string id){}
}

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
7.0.9 498 8/8/2022
7.0.8 485 2/25/2022
7.0.7 481 2/19/2022
7.0.6 454 2/18/2022
7.0.5 475 2/16/2022
7.0.4 479 2/6/2022
7.0.3 493 1/27/2022
7.0.2 475 1/27/2022
7.0.1 472 1/27/2022
7.0.0 477 1/23/2022
6.0.1 486 1/19/2022
6.0.0 330 12/22/2021
5.0.1.1 399 9/12/2021
5.0.1 371 9/8/2021
5.0.0 366 9/6/2021
3.1.3 364 8/28/2021
3.1.2 356 8/28/2021
3.1.1 375 8/28/2021
3.1.0 414 6/30/2021
1.5.6 379 5/12/2021
1.5.4 441 12/7/2020
1.5.3 437 12/7/2020
1.5.2 456 12/7/2020
1.5.1 503 8/16/2020
1.5.0 489 8/15/2020
1.4.8 519 4/16/2020
1.4.6 517 3/28/2020
1.4.5 527 3/15/2020
1.4.4 549 3/15/2020
1.4.2 542 3/15/2020
1.4.1 533 3/12/2020
1.4.0 525 3/11/2020
1.3.8 519 2/14/2020
1.3.5 545 2/14/2020
1.3.4 515 1/30/2020
1.3.3 508 1/30/2020
1.3.2 524 1/30/2020
1.3.1 570 1/7/2020
1.3.0 557 1/7/2020
1.2.9 538 1/7/2020
1.2.8 528 1/7/2020
1.2.2 544 12/26/2019
1.1.9 510 12/1/2019
1.1.8 505 12/1/2019
1.1.7 524 12/1/2019
1.1.6 521 12/1/2019
1.1.3 512 12/1/2019
1.1.2 521 12/1/2019
1.1.1 511 7/25/2019
1.1.0 561 7/15/2019
1.0.9 603 2/26/2020
1.0.8 576 6/1/2019
1.0.7 607 6/1/2019
1.0.6 591 4/10/2019
1.0.5 596 4/10/2019
1.0.4 603 4/10/2019
1.0.3 587 4/10/2019
1.0.2 617 4/10/2019
1.0.1 586 4/10/2019

重构版