OpenRobot.Framework.Web.Core
1.1.0
dotnet add package OpenRobot.Framework.Web.Core --version 1.1.0
NuGet\Install-Package OpenRobot.Framework.Web.Core -Version 1.1.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="OpenRobot.Framework.Web.Core" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenRobot.Framework.Web.Core" Version="1.1.0" />
<PackageReference Include="OpenRobot.Framework.Web.Core" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OpenRobot.Framework.Web.Core --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: OpenRobot.Framework.Web.Core, 1.1.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.
#:package OpenRobot.Framework.Web.Core@1.1.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OpenRobot.Framework.Web.Core&version=1.1.0
#tool nuget:?package=OpenRobot.Framework.Web.Core&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
OpenRobot.Framework.Web.Core
OpenRobot.Framework.Web.Core 是 OpenRobot Web 框架的 Web 层核心组件,提供身份验证、授权、动态 API 控制器生成、Swagger/OpenAPI 文档和 SignalR 实时通信功能。
主要特性
- JWT 身份验证 - 基于 HMAC-SHA256 签名的 JWT Bearer 令牌认证
- 多租户支持 - 完整的多租户架构支持
- 动态 Web API - 自动从应用服务生成 RESTful API 控制器
- Swagger/OpenAPI - 自动生成 API 文档
- CORS 支持 - 跨域资源共享配置
- SignalR 集成 - 实时双向通信
- 自定义连接解析 - 支持多数据库动态连接切换
- 外部认证 - 支持外部身份验证提供程序
安装
dotnet add package OpenRobot.Framework.Web.Core
或在 Visual Studio 的 NuGet 包管理器控制台中运行:
Install-Package OpenRobot.Framework.Web.Core
快速开始
配置 JWT 身份验证
using Microsoft.IdentityModel.Tokens;
using System.Text;
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("YourSecretKey")),
ValidateIssuer = true,
ValidIssuer = "OpenRobotServer",
ValidateAudience = true,
ValidAudience = "OpenRobotClient",
ValidateLifetime = true
};
});
}
}
配置 Swagger
using Microsoft.OpenApi.Models;
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo
{
Title = "OpenRobot API",
Version = "v1",
Description = "OpenRobot Framework API Documentation"
});
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Description = "JWT Authorization header using the Bearer scheme",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.ApiKey
});
});
}
}
配置 CORS
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy("AllowAll", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
}
}
应用服务自动生成 API
using Abp.Application.Services;
using Abp.Domain.Repositories;
public class UserAppService : ApplicationService, IUserAppService
{
private readonly IRepository<User, long> _userRepository;
public UserAppService(IRepository<User, long> userRepository)
{
_userRepository = userRepository;
}
public async Task<UserDto> GetAsync(long id)
{
var user = await _userRepository.GetAsync(id);
return ObjectMapper.Map<UserDto>(user);
}
}
// 自动生成 API: GET /api/services/app/User/Get
依赖项
| 包名 | 版本 | 用途 |
|---|---|---|
| Abp.AspNetCore | 9.4.2 | ABP ASP.NET Core 集成 |
| Abp.ZeroCore | 9.4.2 | ABP Zero Core |
| Abp.AspNetCore.SignalR | 9.4.2 | SignalR 集成 |
| Microsoft.AspNetCore.Authentication.JwtBearer | 8.0.8 | JWT 身份验证 |
| Swashbuckle.AspNetCore | 6.5.0 | Swagger/OpenAPI |
系统要求
- .NET 8.0 或更高版本
- ASP.NET Core 8.0
在框架中的位置
OpenRobot.Framework.Web.Host (Startup)
└── OpenRobot.Framework.Web.Core ✓
├── OpenRobot.Framework.Application ✓
├── OpenRobot.Framework.EFCommon ✓
└── OpenRobot.Framework.EntityFrameworkCore ✓
核心组件
身份验证配置
- JWT Token 生成和验证
- 多租户令牌支持
- 外部认证提供程序集成
动态 API
应用服务自动转换为 RESTful API:
GetAsync(long id)→GET /api/services/app/User/GetCreateAsync(CreateDto input)→POST /api/services/app/User/CreateUpdateAsync(UpdateDto input)→PUT /api/services/app/User/UpdateDeleteAsync(long id)→DELETE /api/services/app/User/Delete
自定义连接解析器
ApressConnectionResolver 支持多数据库动态切换:
- 根据租户或请求上下文选择数据库
- 支持读写分离
- 支持分库分表策略
目录结构
OpenRobot.Framework.Web.Core/
├── Authentication/ # 身份验证配置
│ ├── JwtBearer/
│ └── ExternalAuth/
├── Authorization/ # 授权配置
├── Controllers/ # API 控制器
├── SignalR/ # SignalR Hub
├── Swagger/ # Swagger 配置
├── Configuration/ # 配置
│ └── ApressConnectionResolver.cs
└── WebFrameworkWebCoreModule.cs
相关模块
OpenRobot.Framework.Application- 应用程序服务层OpenRobot.Framework.EntityFrameworkCore- 数据访问层OpenRobot.Framework.Web.Host- 主机应用程序
许可证
本项目采用 MIT 许可证。
作者
OpenRobot
反馈与贡献
欢迎通过以下方式提供反馈:
- 提交 Issue
- 发起 Pull Request
- 联系维护者
| 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Abp.AspNetCore (>= 9.4.2)
- Abp.AspNetCore.SignalR (>= 9.4.2)
- Abp.ZeroCore (>= 9.4.2)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.8)
- OpenRobot.Framework.Application (>= 1.1.0)
- OpenRobot.Framework.EFCommon (>= 1.1.0)
- OpenRobot.Framework.EntityFrameworkCore (>= 1.1.0)
- Swashbuckle.AspNetCore (>= 6.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.