Skip to content

命名规范

命名空间分层

2.0 后命名空间按职责区分:

类型命名空间前缀示例
框架基础设施Yi.Framework.*Yi.Framework.SqlSugarCore
功能/业务模块Yi.Module.*Yi.Module.Rbac.Application
应用组装层Yi.Abp.*Yi.Abp.Web

不要把业务模块命名为 Yi.Framework.{Module}framework 只用于通用基础能力,例如 SqlSugar、缓存、统一返回、操作横切等。

项目命名

业务模块项目使用:

text
Yi.Module.{Module}.Domain.Shared
Yi.Module.{Module}.Domain
Yi.Module.{Module}.Application.Contracts
Yi.Module.{Module}.Application
Yi.Module.{Module}.SqlSugarCore

示例:

text
Yi.Module.Rbac.Domain
Yi.Module.Rbac.Application
Yi.Module.Rbac.Application.Contracts
Yi.Module.Rbac.SqlSugarCore

ABP 模块类命名

项目模块类
Yi.Module.Rbac.DomainYiModuleRbacDomainModule
Yi.Module.Rbac.ApplicationYiModuleRbacApplicationModule
Yi.Framework.SqlSugarCoreYiFrameworkSqlSugarCoreModule
Yi.Abp.WebYiAbpWebModule

规则是:命名空间前缀决定类名前缀,Yi.Module.* 使用 YiModuleYi.Framework.* 使用 YiFramework

类命名

类型命名规则示例
聚合根{Name}AggregateRootUserAggregateRoot
普通实体{Name}EntityUserRoleEntity, DictionaryEntity
值对象{Name}ValueObjectEncryptPasswordValueObject
应用服务{Name}ServiceUserService
领域服务{Name}ManagerUserManager, AccountManager
服务接口I{Name}ServiceIUserService, IRoleService

DTO 命名

输入用 Vo 后缀,输出用 Dto 后缀:

用途命名规则示例
创建输入{Entity}CreateInputVoUserCreateInputVo
更新输入{Entity}UpdateInputVoUserUpdateInputVo
列表查询输入{Entity}GetListInputVoUserGetListInputVo
单条输出{Entity}GetOutputDtoUserGetOutputDto
列表输出{Entity}GetListOutputDtoUserGetListOutputDto

表名规范

数据库表名使用大驼峰,不加项目前缀:

csharp
[SugarTable("User")]
public class UserAggregateRoot : AggregateRoot<Guid>
{
}

推荐:

text
User
Role
Tenant
AuditLog
EntityChange
Setting

不推荐:

text
YiUser
YiTenant
yi_user
rbac_user

只有在确实存在跨模块同名冲突时,才考虑加领域语义前缀,例如 SystemConfig。不要加 Yi 这种项目前缀。

变量命名

  • 私有字段使用下划线前缀:_repository, _userManager, _currentUser
  • 命名空间与文件夹结构一致:Yi.Module.Rbac.Domain.Entities
  • 实体主键类型统一使用 Guid
  • 前端 API 和视图目录使用 kebab-case 或既有业务目录风格,优先保持当前模块一致

相关文档

贡献者

The avatar of contributor named as dubai dubai

页面历史

基于 MIT 许可发布.