|
|
3 months ago | |
|---|---|---|
| .github/workflows | 6 months ago | |
| database | 6 years ago | |
| docs | 2 years ago | |
| src | 1 year ago | |
| test | 3 months ago | |
| .gitattributes | 6 years ago | |
| .gitignore | 6 years ago | |
| Directory.Build.props | 3 months ago | |
| EasyAbp.Abp.Trees.sln | 5 years ago | |
| EasyAbp.Abp.Trees.sln.DotSettings | 6 years ago | |
| LICENSE | 6 years ago | |
| common.props | 3 months ago | |
| docker-compose.migrations.yml | 6 years ago | |
| docker-compose.override.yml | 6 years ago | |
| docker-compose.yml | 6 years ago | |
docs/README.md
Abp.Trees
An abp module that provides standard tree structure entity implement.
Installation
-
Install the following NuGet packages. (see how)
- EasyAbp.Abp.Trees.Domain
- EasyAbp.Abp.Trees.Domain.Shared
- EasyAbp.Abp.Trees.EntityFrameworkCore
-
Add
DependsOn(typeof(AbpTreesXxxModule))attribute to configure the module dependencies. (see how)
Usage
-
Create a entity and implement
ITree<TEntity>. -
Create a Repository for the entity.
EfCoreTreeRepository<TDbContext, TEntity>override some function ofEfCoreRepository<TDbContext, TEntity, TKey>to match tree structure:-
InsertAsync:Auto Append nodeCodeand CalcLevelproperty when insert -
UpdateAsync:Auto Move node when update aEntitythat parentId is modified -
DeleteAsync:Also deleteChildrennodes
-
-
You have two ways to use this
Repository-
Way 1 : Default Repository(
ITreeRepository<>),
Addcontext.Services.AddTreeRepository<MyProjectNameDbContext>();to ConfigureServices method inMyProjectNameEntityFrameworkCoreModule.cs. -
Way 2 : Create a
CustomRepositorythat base onEfCoreTreeRepository<TDbContext, TEntity> -
Example:
context.Services.AddAbpDbContext<TestDbContext>(options => { options.AddDefaultRepositories(includeAllEntities: true);//add Abp's `IRepository<TEntity>` options.AddDefaultTreeRepositories();//add `ITreeRepository<TEntity>` for all Entity with implement `ITree<TEntity>` options.TreeEntity<Resource>(x => x.CodeLength = 10);//set CodeLength for each Entity(Default:5) });``
-
CheckPoints
1.Check the module DependsOn(typeof(AbpTreesXxxModule)) dependencies are config
XxxEntityFrameworkCoreModule, XxxDomainSharedModule, XxxDomainModule
2.Check IYourRepository : ITreeRepository<YourEntity>
3.Be sure YourEntity:XxxEntity<Guid>,ITree<YourEntity>
4.Be sure XxxEntityFrameworkCoreModule has config options.AddDefaultTreeRepositories();
Sample
It works fine with Volo.Abp.Application.Services.CrudAppService.
After replacing IRepository<> with ITreeRepository<Domain.OrganizationUnit>, the repository will handle the tree structure of the entity during creating, updating, and deleting.
public class OrganizationUnitAppService:
Volo.Abp.Application.Services.CrudAppService<
Domain.OrganizationUnit, Application.OrganizationUnitDto,
Application.OrganizationUnitDto,Guid, Volo.Abp.Application.Dtos.IPagedAndSortedResultRequest,
Application.CreateOrganizationUnitDto,Application.UpdateOrganizationUnitDto>,
IOrganizationUnitAppService
{
public OrganizationUnitAppService(
EasyAbp.Abp.Trees.ITreeRepository<Domain.OrganizationUnit> organizationUnitRepository
):base(organizationUnitRepository)
{
}
}
Roadmap
- Widget of tree operation for MVC UI.
- Create a TreeManager to provides more function,example:
Sort(reassigned code),Ui Pagination... - More Unit tests.