Bizer 0.7.0

Suggested Alternatives

Bizer.Core

Additional Details

The package is changed to Bizer.Core

dotnet add package Bizer --version 0.7.0                
NuGet\Install-Package Bizer -Version 0.7.0                
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="Bizer" Version="0.7.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Bizer --version 0.7.0                
#r "nuget: Bizer, 0.7.0"                
#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 Bizer as a Cake Addin
#addin nuget:?package=Bizer&version=0.7.0

// Install Bizer as a Cake Tool
#tool nuget:?package=Bizer&version=0.7.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");//模糊搜索匹配名称的程序集,支持通配符
});

ReturnsResunts<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 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 is compatible.  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 (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.

Version Downloads Last updated
0.7.0 382 1/9/2024 0.7.0 is deprecated because it is no longer maintained.
0.6.1 342 12/26/2023
0.6.0 329 9/4/2023
0.5.0.1 316 8/29/2023
0.5.0 345 8/4/2023
0.4.0 322 7/28/2023
0.3.0 325 7/20/2023
0.2.0 291 7/15/2023
0.1.0 328 7/13/2023