愿你出走半生,归来仍是少年!?
当前项目构成如下:
项目结构
1.Dto
????????Dto作为应用服务的数据传输对象,连接应用与后台的数据交互。根据Abp框架的设定,一般的CrudAppService会具备5个Dto,分别如下:
TGetOutputDto:用于Get接口的返回结果参数,实体详情。 TGetListOutputDto:用于GetList接口的返回结果参数,实体列表项。 TGetListInput:用于GetList接口的请求参数,需继承于PagedAndSortedResultRequestDto TCreateInput:用于Create接口的请求参数,创建实体用。 TUpdateInput:用于Update接口的请求参数,更新实体用。
2.IApplicationService
????????Dto作为应用服务的接口定义,约束实际的应用服务实现,需继承IApplicationService 。若实际为数据库的增删改查,可继承ICrudAppService 接口。
/// <summary>
/// 组织机构应用服务接口
/// </summary>
public interface IOrganizationUnitAppService : ICrudAppService<
OrganizationUnitDetailsDto,
OrganizationUnitDetailsDto,
Guid,
PagedAndSortedResultRequestDto,
OrganizationUnitCreateDto,
OrganizationUnitUpdateDto>
{
/// <summary>
/// 获取树形结构
/// </summary>
/// <returns></returns>
Task<OrganizationUnitTreeDto> GetTreeAsync();
}
/// <summary>
/// 用户认证
/// </summary>
public interface IAuthorizeAppService: IApplicationService
{
/// <summary>
/// 用户登录
/// </summary>
/// <param name="input">登录参数</param>
/// <returns>Token</returns>
[HttpGet]
Task<string> LoginAsync(LoginDto input);
}
3.Permissions
????????Permissions用于整个应用的权限定义,结合Abp的身份认证策略实现权限控制。通过静态类AppPermissions 实现权限策略的静态数据多层级定义;通过AppPermissionDefinitionProvider 实现权限策略的持久化。
/// <summary>
/// 应用的权限
/// </summary>
public static class AppPermissions
{
/// <summary>
/// 项目前缀
/// </summary>
public const string GroupName = "LandManager";
public const string CreateStr = ".Create";
public const string UpdateStr = ".Update";
public const string DeleteStr = ".Delete";
/// <summary>
/// 组织机构
/// </summary>
public static class Organizations
{
/// <summary>
/// 默认权限
/// </summary>
public const string Default = GroupName + ".Organizations";
/// <summary>
/// 创建权限
/// </summary>
public const string Create = Default + CreateStr;
/// <summary>
/// 更新权限
/// </summary>
public const string Update = Default + UpdateStr;
/// <summary>
/// 删除权限
/// </summary>
public const string Delete = Default + DeleteStr;
}
/// <summary>
/// 权限管理
/// </summary>
public static class Permission
{
/// <summary>
/// 默认权限
/// </summary>
public const string Default = GroupName + ".Permission";
/// <summary>
/// 给用户设置权限
/// </summary>
public const string SetForUser = Default + ".SetForUser";
/// <summary>
/// 给角色设置权限
/// </summary>
public const string SetForRole = Default + ".SetForRole";
}
/// <summary>
/// 角色
/// </summary>
public static class Roles
{
/// <summary>
/// 默认权限
/// </summary>
public const string Default = GroupName + ".Roles";
/// <summary>
/// 创建角色权限
/// </summary>
public const string Create = Default + CreateStr;
/// <summary>
/// 删除角色权限
/// </summary>
public const string Delete = Default + DeleteStr;
/// <summary>
/// 更新角色权限
/// </summary>
public const string Update = Default + UpdateStr;
}
/// <summary>
/// 用户
/// </summary>
public static class Users
{
/// <summary>
/// 默认权限
/// </summary>
public const string Default = GroupName + ".Users";
/// <summary>
/// 创建用户权限
/// </summary>
public const string Create = Default + CreateStr;
/// <summary>
/// 更新用户权限
/// </summary>
public const string Update = Default + UpdateStr;
/// <summary>
/// 删除用户权限
/// </summary>
public const string Delete=Default + DeleteStr;
/// <summary>
/// 变更用户组织机构权限
/// </summary>
public const string UpdateOrganizations = Default + ".UpdateOrganizations";
/// <summary>
/// 将用户添加到指定组织机构权限
/// </summary>
public const string AddToOrganization = Default + ".AddToOrganization";
/// <summary>
/// 给用户添加角色
/// </summary>
public const string AddToRole = Default + ".AddToRole";
/// <summary>
/// 移除用户的角色
/// </summary>
public const string RemoveFromRole = Default + "RemoveFromRole";
}
}
public class AppPermissionDefinitionProvider : PermissionDefinitionProvider
{
public override void Define(IPermissionDefinitionContext context)
{
//添加整个应用的最基础权限
var myGroup = context.AddGroup(AppPermissions.GroupName, L("Permission:LandManager"));
#region 组织机构
var organizationPermissions = myGroup.AddPermission(AppPermissions.Organizations.Default,L("Permission:Organization.Default"));
organizationPermissions.AddChild(AppPermissions.Organizations.Create, L("Permission:Organization.Create"));
organizationPermissions.AddChild(AppPermissions.Organizations.Update, L("Permission:Organization.Update"));
organizationPermissions.AddChild(AppPermissions.Organizations.Delete, L("Permission:Organization.Delete"));
#endregion
#region 权限
var permissionPermissions = myGroup.AddPermission(AppPermissions.Permission.Default, L("Permission:Permission.Default"));
permissionPermissions.AddChild(AppPermissions.Permission.SetForUser, L("Permission:Permission.SetForUser"));
permissionPermissions.AddChild(AppPermissions.Permission.SetForRole, L("Permission:Permission.SetForRole"));
#endregion
#region 角色
var rolePermissions = myGroup.AddPermission(AppPermissions.Roles.Default, L("Permission:Roles.Default"));
rolePermissions.AddChild(AppPermissions.Roles.Create, L("Permission:Roles.Create"));
rolePermissions.AddChild(AppPermissions.Roles.Delete, L("Permission:Roles.Delete"));
rolePermissions.AddChild(AppPermissions.Roles.Update, L("Permission:Roles.Update"));
#endregion
#region 用户
var userPermissions = myGroup.AddPermission(AppPermissions.Users.Default, L("Permission:Users.Default"));
userPermissions.AddChild(AppPermissions.Users.Create, L("Permission:Users.Create"));
userPermissions.AddChild(AppPermissions.Users.Delete, L("Permission:Users.Delete"));
userPermissions.AddChild(AppPermissions.Users.Update, L("Permission:Users.Update"));
userPermissions.AddChild(AppPermissions.Users.AddToOrganization, L("Permission:Users.AddToOrganization"));
userPermissions.AddChild(AppPermissions.Users.UpdateOrganizations, L("Permission:Users.UpdateOrganizations"));
userPermissions.AddChild(AppPermissions.Users.AddToRole, L("Permission:Users.AddToRole"));
userPermissions.AddChild(AppPermissions.Users.RemoveFromRole, L("Permission:Users.RemoveFromRole"));
#endregion
}
private static LocalizableString L(string name)
{
return LocalizableString.Create<LandManagerResource>(name);
}
}
?4.模块类
? ? ? ? 无特殊配置,进行模块依赖。
?
[DependsOn(
typeof(LandManagerDomainSharedModule),
typeof(AbpIdentityApplicationContractsModule)
)]
public class LandManagerApplicationContractsModule:AbpModule
{
}