这边推荐SqlSugar,当然也可以用其他ORM,因为是ReZero.Api自带就有的
//可以拿到appsettings.json里面的ConnectionStrings中的DefaultConnection节点 string conn=ApiConfiguration.GetJsonValue<dynamic>("ConnectionStrings").DefaultConnection; //推荐Scoped模式 builder.Services.AddScoped<ISqlSugarClient>(it => { return new SqlSugarClient(new ConnectionConfig() { DbType =DbType.MySql, ConnectionString =conn, IsAutoCloseConnection =true }); }); //更多用法看 SqlSugar文档
随便你扔什么地方,class要有[Api(..)],方法上要有[ApiMethod(..)]
//200100是分类ID,GroupName设置相同会变成一组 [Api(200100, GroupName = "分组3")] public class Class { //属性注入只支持API,非API用构造函数 [DI] public ISqlSugarClient? db { get; set; } [ApiMethod("测方法")] public string Test() { return db!.Ado.GetString("select 1 as id"); } }
你用到的类库一定要在注册rezero的时候加进去就OK
//注册ReZero.Api builder.Services.AddReZeroServices(api => { var apiObj = SuperAPIOptions.GetOptions("rezero.json"); /*有多个dll就写多个*/ var assemblyList = new Assembly[] { Assembly.GetExecutingAssembly() }; apiObj!.DependencyInjectionOptions = new DependencyInjectionOptions(assemblyList); api.EnableSuperApi(apiObj); });
我们新建的类就成了API
返回1说明操作库成功了
rezero+orm.zip 升级rezero.api demo比较老
2016 © donet5.comApache Licence 2.0