Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Abp.GeneralTree #5851


User avatar
0
statuscast created

Hi,

Trying to build an entity that uses Abp.GeneralTree.

Step 1: Define entity

namespace StatusCast.Components
{
public interface IComponent : IEntity
{
}

public partial class Component : Entity<long>, IComponent, IGeneralTree<Component, long>, 
    IExtendableObject, ICreationAudited, IMustHaveTenant, ISoftDelete
{
    // Abp built in
    public string ExtensionData { get; set; }
    public virtual DateTime CreationTime { get; set; }
    public int TenantId { get; set; }
    public bool IsDeleted { get; set; }
    public long? CreatorUserId { get; set; }
    // more...

Step 2: Add to EF

public class MyDbContext : AbpZeroDbContext<Tenant, Role, User, StatusCastDbContext>, IAbpPersistedGrantDbContext
{
        // StatusCast Entities
        public virtual DbSet<Component> Components { get; set; }
}

Step 3: Create basic AppService:

public class ComponentAppService : MyAppServiceBase, IComponentAppService
{
        private readonly IGeneralTreeManager<Component, long> _componentTreeManager;

        public ComponentAppService(IGeneralTreeManager<Component, long> componentTreeManager)
        {
            _componentTreeManager = componentTreeManager;
        }

        public async Task<long> CreateComponentAsync(ComponentCreateDto input)
        {
            var component = ObjectMapper.Map<Component>(input);
            await _componentTreeManager.CreateAsync(component);
            return component.Id;
        }
 }

Step 4: Call it via a controller:

[Route("api/[controller]/[action]")]
    public class ComponentsController : StatusCastControllerBase
    {
        private readonly IComponentAppService _componentsService;

        public ComponentsController(
            IComponentAppService componentsService
        )
        {
            _componentsService = componentsService;
        }

        [ApiExplorerSettings(GroupName = "public")]
        [HttpPost]
        [Route("/api/Component")]
        public async Task<long> Create(ComponentCreateDto input)
        {
            return await _componentsService.CreateComponentAsync(input);

        }

    }

=============================================== When calling the controller, I am getting the following error:

Exception thrown: 'Castle.MicroKernel.Handlers.HandlerException' in Castle.Windsor.dll Exception thrown: 'Castle.MicroKernel.Handlers.HandlerException' in Castle.Windsor.dll Exception thrown: 'Castle.MicroKernel.Handlers.HandlerException' in System.Private.CoreLib.dll 'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.1.5\System.Diagnostics.StackTrace.dll'. Cannot find or open the PDB file. 'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.1.5\System.Reflection.Metadata.dll'. Cannot find or open the PDB file. Abp.AspNetCore.Mvc.ExceptionHandling.AbpExceptionFilter: 2018-10-28 10:30:37,119 [20] ERROR Abp.AspNetCore.Mvc.ExceptionHandling.AbpExceptionFilter Can't create component 'StatusCast.Components.ComponentAppService' as it has dependencies to be satisfied.

'StatusCast.Components.ComponentAppService' is waiting for the following dependencies:

  • Service 'Abp.GeneralTree.IGeneralTreeManager`2[[StatusCast.Components.Component, StatusCast.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Int64, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' which was not registered.

Castle.MicroKernel.Handlers.HandlerException: Can't create component 'StatusCast.Components.ComponentAppService' as it has dependencies to be satisfied.

'StatusCast.Components.ComponentAppService' is waiting for the following dependencies:

  • Service 'Abp.GeneralTree.IGeneralTreeManager`2[[StatusCast.Components.Component, StatusCast.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Int64, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' which was not registered. at Castle.MicroKernel.Handlers.DefaultHandler.AssertNotWaitingForDependency() at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate constructor, CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy) at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy) at Castle.Windsor.MsDependencyInjection.ScopedWindsorServiceProvider.GetServiceInternal(Type serviceType, Boolean isOptional) in D:\Github\castle-windsor-ms-adapter\src\Castle.Windsor.MsDependencyInjection\ScopedWindsorServiceProvider.cs:line 55 at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<&gt;c__DisplayClass5_0.g__CreateController|0(ControllerContext controllerContext) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()

============================================================

I have a feeling there is some additional startup code I need to do to get Abp.TreeManager properly available, but don't really know what that would be as there is very little documentation. Any help would be appreciated.

thanks! jasen


3 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    I believe you're missing a DependsOn:

    [DependsOn(typeof(GeneralTreeModule))]
    public class StatusCastCoreModule : AbpModule
    

    Note that Abp.GeneralTree is not an official ABP package.

  • User Avatar
    0
    statuscast created

    That seems to have done the trick. Couldn't find that anywhere in any docs, so thank you.

    IMHO, Abp.GeneralTree should be. It's another great little utiility component that almost every SaaS vendor needs. Since you have it built already, why not just throw it in? ;-)

  • User Avatar
    0
    maliming created
    Support Team

    @statuscast I am the author of Abp.GeneralTree, thank you very much for your approval. I will add detailed instructions in GeneralTree Documents .

    I thought about merging into abp before, but I think it's better as a stand-alone component (because fixing bugs, updating new versions is quick and easy) If you have questions, you can go to https://github.com/maliming/Abp.GeneralTree/issues to communicate.