OpenRobot.Framework.Application
1.1.0
dotnet add package OpenRobot.Framework.Application --version 1.1.0
NuGet\Install-Package OpenRobot.Framework.Application -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.Application" 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.Application" Version="1.1.0" />
<PackageReference Include="OpenRobot.Framework.Application" />
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.Application --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: OpenRobot.Framework.Application, 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.Application@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.Application&version=1.1.0
#tool nuget:?package=OpenRobot.Framework.Application&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
OpenRobot.Framework.Application
OpenRobot.Framework.Application 是 OpenRobot Web 框架的应用程序服务层,包含数据传输对象 (DTO)、应用服务 (Application Services)、AutoMapper 配置和授权定义。
主要特性
- 应用服务 - 提供业务逻辑的应用服务接口和实现
- DTO 定义 - 数据传输对象,用于客户端与服务器之间的数据交换
- AutoMapper 配置 - 实体与 DTO 之间的自动映射配置
- 授权提供程序 - 应用程序权限定义和管理
- 验证规则 - DTO 的数据验证规则
- API 控制器自动生成 - 通过动态 Web API 自动生成 RESTful 接口
安装
dotnet add package OpenRobot.Framework.Application
或在 Visual Studio 的 NuGet 包管理器控制台中运行:
Install-Package OpenRobot.Framework.Application
快速开始
定义应用服务
using Abp.Application.Services;
using Abp.Domain.Repositories;
public class MyEntityAppService : ApplicationService, IMyEntityAppService
{
private readonly IRepository<MyEntity, long> _repository;
public MyEntityAppService(IRepository<MyEntity, long> repository)
{
_repository = repository;
}
public async Task<MyDto> CreateAsync(CreateMyDto input)
{
var entity = ObjectMapper.Map<MyEntity>(input);
return await _repository.InsertAsync(entity);
}
public async Task<MyDto> GetAsync(long id)
{
var entity = await _repository.GetAsync(id);
return ObjectMapper.Map<MyDto>(entity);
}
}
定义 DTO
using Abp.AutoMapper;
using System.ComponentModel.DataAnnotations;
[AutoMapTo(typeof(MyEntity))]
public class CreateMyDto
{
[Required]
[StringLength(MaxLength)]
public string Name { get; set; }
public string Description { get; set; }
}
[AutoMapFrom(typeof(MyEntity))]
public class MyDto
{
public long Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
配置授权
using Abp.Authorization;
public class MyAppAuthorizationProvider : AuthorizationProvider
{
public override void SetPermissions(IPermissionDefinitionContext context)
{
var myGroup = context.CreatePermission("MyApp");
myGroup.CreateChildPermission("MyApp.Create");
myGroup.CreateChildPermission("MyApp.Update");
myGroup.CreateChildPermission("MyApp.Delete");
myGroup.CreateChildPermission("MyApp.GetAll");
}
}
目录结构
OpenRobot.Framework.Application/
├── Authorization/ # 授权定义
│ ├── AppAuthorizationProvider.cs
│ └── Permissions.cs
├── Lists/ # 列表 DTO
├── Objects/ # 对象 DTO
├── Services/ # 应用服务
│ └── ...
└── MapperProfile.cs # AutoMapper 配置
在框架中的位置
OpenRobot.Framework.Web.Core
└── OpenRobot.Framework.Application ✓
├── OpenRobot.Framework.Common ✓
└── OpenRobot.Framework.Core ✓
核心概念
应用服务层
应用服务层位于展示层和领域层之间,负责:
- 协调业务逻辑
- 数据验证
- 权限检查
- 实体与 DTO 之间的转换
DTO 命名约定
Create{Entity}Dto- 创建实体Update{Entity}Dto- 更新实体{Entity}Dto- 查询实体Get{Entity}Input- 查询输入参数Paged{Entity}ResultRequestDto- 分页请求
相关模块
OpenRobot.Framework.Core- 领域实体和业务逻辑OpenRobot.Framework.Common- 公共组件库OpenRobot.Framework.Web.Core- Web 层(自动生成 API 控制器)
许可证
本项目采用 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
- OpenRobot.Framework.Common (>= 1.1.0)
- OpenRobot.Framework.Core (>= 1.1.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on OpenRobot.Framework.Application:
| Package | Downloads |
|---|---|
|
OpenRobot.Framework.Web.Core
OpenRobot.Framework.Web.Core 是 Web 层核心组件,提供身份验证、授权、API 控制器和 Swagger 配置 |
GitHub repositories
This package is not used by any popular GitHub repositories.