Open Closed

Autofac.Core.DependencyResolutionException #8789


User avatar
0
leeneshk created
  • ABP Framework version: v9.0.2

  • UI Type: Angular

  • Database System: EF Core (SQL Server)

  • Tiered (for MVC) or Auth Server Separated (for Angular): yes

  • Exception message and full stack trace:
    Hello,

I am getting a circular dependency error on my solution when attempting to consume a third-party API (Learnworlds), I have created the App Service, the required interfaces as well as a repo method that gets the details for the API call. All I want to do is get data upon request and populate certain fields, any assistance will be extremely helpful as I have been struggling with this issue for a few days now.

An exception was thrown while activating EDOnlineT3.Controllers.LearnworldsServices.LearnworldsApiController -> λ:EDOnlineT3.LearnworldsServices.ILearnworldsApiService. at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext context) at Autofac.Core.Pipeline.ResolvePipeline.Invoke(ResolveRequestContext context) at Autofac.Core.Resolving.Middleware.RegistrationPipelineInvokeMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext context) at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext context) at Autofac.Core.Resolving.Middleware.ScopeSelectionMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext context) at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action1 next) at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext context) at Autofac.Core.Pipeline.ResolvePipeline.Invoke(ResolveRequestContext context) at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest& request) at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest& request) at Autofac.Core.Resolving.ResolveOperation.Execute(ResolveRequest& request) at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(ResolveRequest& request) at Autofac.Core.Lifetime.LifetimeScope.Autofac.IComponentContext.ResolveComponent(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 Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType, IEnumerable1 parameters) at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType) at Autofac.Extensions.DependencyInjection.AutofacServiceProvider.GetRequiredService(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)

I would like to have a call with any one of you guys perhaps, so that we can go through the issue together, if possible


14 Answer(s)
  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hello Leeneshk,

    If you share your ILearnworldsApiService and LearnworldsApiController constructor dependencies, We can provide more specific guidance.

  • User Avatar
    0
    leeneshk created

    Hello @berkansasmaz,

    This is my LearnworldsApiService:
    image.png

    This is my ILearnworldsApiService:

    image.png

    And then my LearnworldsApiController:

    image.png

    I have also created .Extended classes for each because I thought it was a standard within abp.io

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hi,

    First of all, you don't need to create an extended of each class. This is a feature to allow customization when code is generated with Suite. See more: https://abp.io/docs/latest/suite/customizing-the-generated-code

    Secondly, you don't need to create a controller, ABP creates the controller for you from ApplicationService. But you can still create it if you want to, of course. See more: https://abp.io/docs/latest/framework/api-development/auto-controllers

    In your case, there should be a structure like the one below:

    ILearnworldsApiService:

    public interface ILearnworldsApiService : IApplicationService
    {
      Task<LookupDto<LearnwroldsActivitiesDto>> GetActivitiesBySchoolAsync(Guid tenantId);
    }
    

    LearnworldsApiService:

    public class LearnworldsApiService : MyAppService, ILearnworldsApiService
    {
        private readonly IMyRepository _myRepository;
        private readonly MyLearnManager _myLearnManager;
    
        public AuthorAppService(
            IMyRepository myRepository,
            MyLearnManager myLearnManager)
        {
            _myRepository = myRepository;
            _myLearnManager = myLearnManager;
        }
    
         public async Task> GetActivitiesBySchoolAsync(Guid tenantId)    
         {
             // ....
         }
    }
    

    LearnworldsApiController:

    You don't need it, but if you want to create it, you can create it similar to this one here: https://github.com/abpframework/abp/blob/dev/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs

  • User Avatar
    0
    leeneshk created

    Hi,

    First of all, you don't need to create an extended of each class. This is a feature to allow customization when code is generated with Suite. See more: https://abp.io/docs/latest/suite/customizing-the-generated-code

    Secondly, you don't need to create a controller, ABP creates the controller for you from ApplicationService. But you can still create it if you want to, of course. See more: https://abp.io/docs/latest/framework/api-development/auto-controllers

    In your case, there should be a structure like the one below:

    ILearnworldsApiService:

    public interface ILearnworldsApiService : IApplicationService 
    { 
      Task<LookupDto<LearnwroldsActivitiesDto>> GetActivitiesBySchoolAsync(Guid tenantId); 
    } 
    

    LearnworldsApiService:

    public class LearnworldsApiService : MyAppService, ILearnworldsApiService 
    { 
        private readonly IMyRepository _myRepository; 
        private readonly MyLearnManager _myLearnManager; 
     
        public AuthorAppService( 
            IMyRepository myRepository, 
            MyLearnManager myLearnManager) 
        { 
            _myRepository = myRepository; 
            _myLearnManager = myLearnManager; 
        } 
     
         public async Task> GetActivitiesBySchoolAsync(Guid tenantId)     
         { 
             // .... 
         } 
    } 
    

    LearnworldsApiController:

    You don't need it, but if you want to create it, you can create it similar to this one here: https://github.com/abpframework/abp/blob/dev/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs

    Thank you for the response, I appreciate it,

    So question though, I need to use the APIService and bind it to another Controller/action, which will populate a dropdown, I initially also tried injecting the service yet still got the dependency injection exception. Also the manager class, do I need that? I have not created a LearnworldsApiManager class though

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    So question though, I need to use the APIService and bind it to another Controller/action, which will populate a dropdown, I initially also tried injecting the service yet still got the dependency injection exception.

    Do not inject a controller into an ApplicationService, instead inject the corresponding repository service directly, or worst case inject the corresponding AppService.

    Also the manager class, do I need that? I have not created a LearnworldsApiManager class though

    This is completely up to your domain. Creating a Domain Service is especially needed when;

    • You implement a core domain logic that depends on some services (like repositories or other external services).

    • The logic you need to implement is related to more than one aggregate/entity, so it doesn't properly fit in any of the aggregates.

    See more: https://abp.io/docs/latest/framework/architecture/domain-driven-design/domain-services

    Note: If you feel unfamiliar with this, don't worry. Once you complete the BookStore tutorial, you will be much more familiar with these topics.


    In this project, information about Author is also shown in Book UI. You can examine BookAppService to see what is done for this:

    https://github.com/abpframework/abp-samples/blob/f34c5797fedc84445d2db403b9d7248f620f2ed4/BookStore-Angular-MongoDb/aspnet-core/src/Acme.BookStore.Application/Books/BookAppService.cs#L25

    If you want to know more about this, I recommend you to follow our BookStore tutorial. See: https://abp.io/docs/latest/tutorials/book-store?UI=NG&DB=EF

  • User Avatar
    0
    leeneshk created

    Thank you very much for the help @berkansasmaz

    I will utilize the feedback provided and get things working again :)

  • User Avatar
    0
    leeneshk created

    Hello @berkansasmaz

    I am not getting any luck, still getting the dependency injection errors, even after using the above,

    Could I perhaps have a call with you on this?

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Hello,

    If it is appropriate, you can send your sample application to support@abp.io with a text like below:

    Please forward my mail to Berkan Sasmaz regarding ticket #8789.

  • User Avatar
    0
    leeneshk created

    Hello,

    If it is appropriate, you can send your sample application to support@abp.io with a text like below:

    Please forward my mail to Berkan Sasmaz regarding ticket #8789.

    Hi Berkan,

    Uhm so I have quite a few dependent components which would cause errors, is that fine still?

    I would prefer if we could have a call via Zoom or Microsoft teams so that I can take you through everything where the error points are.

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    If you are available, we can talk right now through this link: https://us04web.zoom.us/j/73615342418?pwd=QIVbN3sQWP4lZ324DtruyDEZkfDvXA.1

  • User Avatar
    0
    leeneshk created

    Thank you so much, I am joining now

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer
  • User Avatar
    0
    leeneshk created

    The document mentioned during the meeting: https://abp.io/docs/latest/framework/architecture/multi-tenancy#change-the-current-tenant

    Thank you very much for your time Berkan,

    I appreciate it, I will keep you posted on the progress, take care

  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    Thank you too :)

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.2.0-preview. Updated on March 13, 2025, 04:08