Bizer 0.6.0
See the version list below for details.
dotnet add package Bizer --version 0.6.0
NuGet\Install-Package Bizer -Version 0.6.0
<PackageReference Include="Bizer" Version="0.6.0" />
paket add Bizer --version 0.6.0
#r "nuget: Bizer, 0.6.0"
// Install Bizer as a Cake Addin #addin nuget:?package=Bizer&version=0.6.0 // Install Bizer as a Cake Tool #tool nuget:?package=Bizer&version=0.6.0
Bizer
作为定义、规则、扩展的核心类
路由
接口定义 ApiRouteAttribute
,实现 HTTP 的路由前缀,同 Controller
里的 HttpRouteAttribute
[ApiRoute("api/users")] //生成 http://localhost/api/users
public interface IUserManager
{
}
不支持 mvc 中的 [controller]
关键字
没有定义该特性的接口不会自动识别成 API 和发送 HTTP 请求。
Http 方法(HttpMethod)
接口方法上定义,同 MVC 方式使用:以下是对照表格
Mvc | Bizer |
---|---|
HttpGet | Get |
HttpPost | Post |
HttpPut | Put |
HttpDelete | Delete |
HttpPatch | Patch |
HttpOptions | Options |
HttpTrace | Trace |
示例:
[ApiRoute("api/users")]
public interface IUserService
{
[Post]
Task CreateAsync()
}
参数
参数默认是 query string
,即 ?arg1=value1&arg2=value2...
类似于 mvc 的 FromQueryAttribute
,映射关系如下:
|Mvc|Bizer|备注|
|---|---|---|
|FromRoute|Path|路由中可模板参数,如{id}|
|FromQuery|Query|
|FromHeader|Header|自动加入到 Header 中
|FromForm|Form|会自动使用 form/data 方式|
|FromBody|Body|用 body 提交,默认使用 application/json 的方式|
示例:
[ApiRoute("api/users")]
public interface IUserService
{
[Post]
Task CreateAsync([Body]User user)
[Get("{id}")]
Task<User> GetAsync([Path]int id)
}
配置
在 Program.cs
中注册服务和配置:
services.AddBizer(options=>{
//配置自动程序集发现,目的是为之后的模块使用
options.Assemblies.Add(typeof(xxx).Assembly); //添加自动发现的程序集
options.AssemblyNames.Add("MyAssembly.*.Service");//模糊搜索匹配名称的程序集,支持通配符
});
Returns
和 Resunts<TResult>
返回值类型
该类型将返回 Code
Messages
Succeed
Data
四个基本属性。
public Task<Returns> GetAsync() //无返回数据
{
if(xxxx)
{
return Returns.Failed("错误信息");
}
return Returns.Success();
}
public Task<Returns<Data>> GetAsync() //有返回数据
{
if(xxxx)
{
return Returns<Data>.Failed("错误信息");
}
return Returns<Data>.Success(data);//一般是成功后才设置数据返回
}
扩展功能
- 开启接口使用
InjectServiceAttribute
作为服务自动注入
builder.AddBizer().AddServiceInjection();
[InjectService] //默认 scoped
public interface IUserService { }
[InjectService(ServiceLifetime.Transient)] //改变生命周期
public interface IRoleService { }
- 使用线程用户作为
ICurrentPrincipalAccessor
服务
builder.AddBizer().AddThreadCurrentPrincipalAccessor();
Product | Versions 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 is compatible. 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. |
-
net6.0
- LazyCache (>= 2.4.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Hosting (>= 6.0.0)
- Microsoft.Extensions.Localization.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
-
net7.0
- LazyCache (>= 2.4.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Hosting (>= 7.0.0)
- Microsoft.Extensions.Localization.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Options (>= 7.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Bizer:
Package | Downloads |
---|---|
Bizer.Services
基于 EntityFrameworkCore 作为 ORM,使用 Mapster 作为映射,实现基本的 CRUD 功能。 |
|
Bizer.Localization
使用 JSON 文件作为本地化资源文件。 |
GitHub repositories
This package is not used by any popular GitHub repositories.