FeiNuo.Core
1.0.1
dotnet add package FeiNuo.Core --version 1.0.1
NuGet\Install-Package FeiNuo.Core -Version 1.0.1
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="FeiNuo.Core" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FeiNuo.Core --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FeiNuo.Core, 1.0.1"
#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 FeiNuo.Core as a Cake Addin #addin nuget:?package=FeiNuo.Core&version=1.0.1 // Install FeiNuo.Core as a Cake Tool #tool nuget:?package=FeiNuo.Core&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FeiNuo
这是一个开发WebApi的通用辅助类库,基于Net8开发
服务自动注入
统一的异常处理
登录、认证、鉴权
操作日志记录功能
预设常用数据模型、工具类、扩展方法
使用说明
Program.cs
// 分布式缓存要在AddAppServices之前注入,默认会注入内存缓存
// services.AddStackExchangeRedisCache();
// 自定义操作日志服务在AddAppServices之前注入
// services.AddSingleton<ILogService, CustomLogSaveService>();
// 注入各项服务,内部会注入内存缓存和分布式内存缓存,
builder.Services.AddAppServices();
// 注入控制器,异常处理程序,配置格式化规则,配置数据校验不通过的返回数据格式
builder.Services.AddAppControllers();
// 注入自定义Token处理程序或登录服务
// builder.Services.AddSingleton<ITokenService, CustomTokenService>();
// builder.services.AddScoped<ILoginService, LoginService>();
// 注入登录接口所需用户数据的实现类,可以这里注入,也可使用属性[Service]
builder.services.AddScoped<ILoginUserService, UserService>();
// 注入认证处理程序
builder.Services.AddAppSecurity(builder.Configuration);
FeiNuo.core
一、服务自动注入(两种方式)
- 继承基类
BaseService
- 标注属性
[ServiceAttribute]
二、统一的异常处理
- 拦截MessageException异常,返回422状态码
- 其它异常返回500状态码,记录错误日志
三、登录、认证、鉴权
登录
- 实现接口 登录,退出,查询用户, 验证码
- 登 录 : POST: /login , 必须参数 username,password
- 退 出 : POST: /logout 退出登录,作废token
- 用 户 : GET: /userinfo 返回LoginUser信息
- 验证码:GET:/captcha 生成验证码
- 可完全自定义登录实现类,只需实现接口ILoginService, 并在调用service.AddAppSecurity之前注入实现类即可。
- 如果使用默认的实现类需实现接口ILoginUserService,返回用户名,密码以及对应的角色权限
认证
- 系统采用Token的方式实现认证。
- 目前有两种Token实现方案,Jwt或Cache,也可以自定义实现。
- 配置项:FeiNuo:Security:TokenType=Cache/Jwt/Other
默认采用Jwt实现,可通过配置项调整; 使用Cache方式需注入分布式缓存(如Redis),系统默认使用内存缓存,重启后会丢失; 自定义实现只需实现接口ITokenService,并把实现类注入到框架里
鉴权
- 字符串鉴权:
[Permission("system:user:add")]
- 超管权限: 用户是SuperAdmin或有SuperAdmin角色的用户拥有所有权限
FeiNuo.Core.Excel
使用NPOI操作Excel, 提供ExcelExporter和ExcelImporter两个主要辅助类实现Excel的导出和导入功能。
Excel导出组件 ExcelExporter
var exporter = new ExcelExporter();
exporter.AddTitleRow(0, "部门名称", "用户名", "手机号码", "电子邮箱", "性别", "用户状态");
int rowIndex = 1;
foreach (var dto in dataList)
{
exporter.AddDataRow(rowIndex++, 0, dto.DeptName, dto.Username, dto.Cellphone, dto.Email, dto.GenderName, dto.StatusName);
}
var bytes = exporter.GetExcelData();
return File(bytes, "application/vnd.ms-excel", $"用户导出{DateTime.Now:yyyyMMddHHmmss}.xlsx");
Excel导入组件 ExcelImporter
// TODO:
常见问题
- linux发布后验证码报错。
大概率是没有字体文件。两种方式解决:
- 复制字体到 /usr/share/fonts
- 在项目根路径下加Fonts文件中,存放ttf字体文件 系统会先查找操作系统下的字体文件,没有的话再找根目录下Fonts文件夹里的字体(*.ttf)
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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.
-
net8.0
- Dapper (>= 2.1.35)
- Microsoft.EntityFrameworkCore (>= 8.0.3)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.3)
- NPOI (>= 2.7.0)
- SixLabors.ImageSharp.Drawing (>= 2.1.2)
- System.IdentityModel.Tokens.Jwt (>= 7.5.0)
- UAParser (>= 3.1.47)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
完善第一版预设的所有功能