Open Closed

Cannot resolve the dependency #7757


User avatar
0
sgarad created
  • ABP Framework version: 8.2.0
  • UI Type: Angular
  • Database System: MySQL
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
  • An exception was thrown while activating CastandCrew.PSL.VendorManagement.Samples.SampleController.
  • at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest& request) at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest& request) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.
  • Steps to reproduce the issue: I have create a new custom module and micro service. In my module I have below entity,appservice and controller. When accessing the the controller from swagger/UI I received the above error.

Entity

  public class Vendors : Entity&lt;int&gt;, ICreationAuditedObject
  {      
      [MaxLength(128)]
      public string Name { get; set; }
      public DateTime CreationTime { get; set; }
      public Guid? CreatorId { get; set; }
      internal Vendors(string name)
      {
          Name= name;
          CreationTime = DateTime.Now;
          CreatorId = Guid.NewGuid();
      }
  }

App Service

 public class VendorAppService : VendorManagementAppService, IVendorManagementAppService
 {
     private readonly VendorManager _vendorManager;
     private readonly IRepository&lt;Vendors, int&gt; _vendorRepository;

     public VendorAppService(VendorManager vendorManager, IRepository&lt;Vendors, int&gt; vendorRepository)
     {
         _vendorManager = vendorManager;
         _vendorRepository = vendorRepository;
         ObjectMapperContext = typeof(VendorManagementApplicationModule);
     }


     [Authorize(VendorManagementPermissions.Vendors.Create)]
     public async Task&lt;VendorDto&gt; CreateAsync(VendorDto vendor)
     {
         var vendor1 = await _vendorManager.CreateAsync(
              vendor.Name
          );

         return ObjectMapper.Map&lt;Vendors, VendorDto&gt;(vendor1);
     }



     [Authorize(VendorManagementPermissions.Vendors.Delete)]
     public async Task DeleteAsync(int id)
     {
         await _vendorRepository.DeleteAsync(id);
     }



     public async Task&lt;ListResultDto&lt;VendorDto&gt;> GetAllAsync()
     {
         var vendors = await _vendorRepository.GetListAsync();
         return new ListResultDto&lt;VendorDto&gt;(
             ObjectMapper.Map&lt;List&lt;Vendors&gt;, List&lt;VendorDto&gt;>(vendors)
         );
     }

     public async Task&lt;VendorDto&gt; GetAsync(int id)
     {
         return ObjectMapper.Map&lt;Vendors, VendorDto&gt;(await _vendorRepository.GetAsync(id));
     }


     [Authorize(VendorManagementPermissions.Vendors.Create)]
     public async Task&lt;VendorDto&gt; UpdateAsync(VendorDto input)
     {
         var vendor = await _vendorRepository.GetAsync(input.Id);

         vendor.Name = input.Name;

         await _vendorRepository.UpdateAsync(vendor);

         return ObjectMapper.Map&lt;Vendors, VendorDto&gt;(vendor);
     }
 }

Controller

[Area(VendorManagementRemoteServiceConsts.ModuleName)]
[RemoteService(Name = VendorManagementRemoteServiceConsts.RemoteServiceName)]
public class VendorController : IVendorManagementAppService
{
    private readonly IVendorManagementAppService _vendorManagementAppService;

    public VendorController(IVendorManagementAppService vendorManagementAppService)
    {
        _vendorManagementAppService = vendorManagementAppService;
    }

    [Authorize]
    public Task&lt;VendorDto&gt; CreateAsync(VendorDto vendor)
    {
        return _vendorManagementAppService.CreateAsync(vendor);

    }

    [Authorize]
    public Task DeleteAsync(int id)
    {
        return _vendorManagementAppService.DeleteAsync(id);
    }

    public Task&lt;VendorDto&gt; GetAsync(int id)
    {
        return _vendorManagementAppService.GetAsync(id);
    }

    [Authorize]
    public Task&lt;ListResultDto&lt;VendorDto&gt;> GetAllAsync()
    {
        return _vendorManagementAppService.GetAllAsync();
    }


    [Authorize]
    public Task&lt;VendorDto&gt; UpdateAsync(VendorDto vendor)
    {
        return _vendorManagementAppService.UpdateAsync(vendor);
    }
}

Module configuration to include the repositories

 public override void ConfigureServices(ServiceConfigurationContext context)
 {
     context.Services.AddAbpDbContext&lt;VendorManagementDbContext&gt;(options =>
     {
         options.AddDefaultRepositories(includeAllEntities: true);        
     });
 }

Above all code is written in DDD module and reference through the micro-service. Is there anything that I'm missing?


4 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    can you share the full error logs

  • User Avatar
    0
    sgarad created

    Hi,

    can you share the full error logs

    8/22/2024 1:47:16 AM [Information] Request starting "HTTP/1.1" "GET" "http"://"localhost:44323""""/api/vendor-management/vendor""" - null null 8/22/2024 1:47:16 AM [Information] Executing endpoint '"CastandCrew.PSL.VendorManagement.VendorController.VendorController.GetAllAsync (CastandCrew.PSL.VendorManagement.HttpApi)"' 8/22/2024 1:47:16 AM [Information] Route matched with "{area = "vendorManagement", action = "GetAll", controller = "Vendor", page = ""}". Executing controller action with signature "System.Threading.Tasks.Task1[Volo.Abp.Application.Dtos.ListResultDto1[CastandCrew.PSL.VendorManagement.Vendor.VendorDto]] GetAllAsync()" on controller "CastandCrew.PSL.VendorManagement.VendorController.VendorController" ("CastandCrew.PSL.VendorManagement.HttpApi"). 8/22/2024 1:47:16 AM [Error] ---------- RemoteServiceErrorInfo ---------- { "code": null, "message": "An internal error occurred during your request!", "details": null, "data": { "ActivatorChain": "CastandCrew.PSL.VendorManagement.VendorController.VendorController" }, "validationErrors": null }

    8/22/2024 1:47:16 AM [Error] Autofac.Core.DependencyResolutionException: An exception was thrown while activating CastandCrew.PSL.VendorManagement.VendorController.VendorController. ---> Autofac.Core.DependencyResolutionException: None of the constructors found on type 'CastandCrew.PSL.VendorManagement.VendorController.VendorController' can be invoked with the available services and parameters: Cannot resolve parameter 'CastandCrew.PSL.VendorManagement.Vendor.IVendorManagementAppService vendorManagementAppService' of constructor 'Void .ctor(CastandCrew.PSL.VendorManagement.Vendor.IVendorManagementAppService)'.

    See https://autofac.rtfd.io/help/no-constructors-bindable for more info. at Autofac.Core.Activators.Reflection.ReflectionActivator.<>c__DisplayClass14_0.<UseSingleConstructorActivation>b__0(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Builder.RegistrationBuilder3.<>c__DisplayClass41_0.<PropertiesAutowired>b__0(ResolveRequestContext context, Action1 next) at Autofac.Builder.RegistrationBuilder3.<>c__DisplayClass39_0.<OnActivated>b__0(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next) --- End of inner exception stack trace --- at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest& request) at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest& request) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() --- End of stack trace from previous location --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

    8/22/2024 1:47:16 AM [Error] ---------- Exception Data ---------- ActivatorChain = CastandCrew.PSL.VendorManagement.VendorController.VendorController

    8/22/2024 1:47:16 AM [Information] Executing "ObjectResult", writing value of type '"Volo.Abp.Http.RemoteServiceErrorResponse"'. 8/22/2024 1:47:16 AM [Information] Executed action "CastandCrew.PSL.VendorManagement.VendorController.VendorController.GetAllAsync (CastandCrew.PSL.VendorManagement.HttpApi)" in 6.6256ms 8/22/2024 1:47:16 AM [Information] Executed endpoint '"CastandCrew.PSL.VendorManagement.VendorController.VendorController.GetAllAsync (CastandCrew.PSL.VendorManagement.HttpApi)"' 8/22/2024 1:47:16 AM [Information] Request finished "HTTP/1.1" "GET" "http"://"localhost:44323""""/api/vendor-management/vendor""" - 500 null "application/json; charset=utf-8" 20.7208ms

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    None of the constructors found on type 'CastandCrew.PSL.VendorManagement.VendorController.VendorController' can be invoked with the available services and parameters: Cannot resolve parameter 'CastandCrew.PSL.VendorManagement.Vendor.IVendorManagementAppService vendorManagementAppService' of constructor 'Void .ctor(CastandCrew.PSL.VendorManagement.Vendor.IVendorManagementAppService)'.

    it seems like some services are not registered in the IOC.

    public class VendorAppService : VendorManagementAppService, IVendorManagementAppService

    Please rename IVendorManagementAppService to IVendorAppService

    public interface IVendorAppService : IApplicationService
    ...
    
    
    public class VendorAppService : VendorManagementAppService, IVendorAppService
    ...
    
  • User Avatar
    0
    sgarad created

    Resolved thanks.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38