Open Closed

Autofac.Core.DependencyResolutionException #8176


User avatar
0
duongdangquoc@gmail.com created
  • ABP Framework version: vX.X.X

  • UI Type: MVC

  • Database System: EF Core (SQL Server)

  • Exception message and full stack trace:
    [ERR] An exception was thrown while activating TSD.DOCS.AdminCategoryService.ListOrganizations.ListOrganizationController -> TSD.DOCS.AdminCategoryService.ListOrganizations.ListOrganizationsAppService.
    Autofac.Core.DependencyResolutionException: An exception was thrown while activating TSD.DOCS.AdminCategoryService.ListOrganizations.ListOrganizationController -> TSD.DOCS.AdminCategoryService.ListOrganizations.ListOrganizationsAppService.
    ---> Autofac.Core.DependencyResolutionException: None of the constructors found on type 'TSD.DOCS.AdminCategoryService.ListOrganizations.ListOrganizationsAppService' can be invoked with the available services and parameters:
    Cannot resolve parameter 'TSD.DOCS.AdminCategoryService.ListOrganizations.IListOrganizationRepository listOrganizationRepository' of constructor 'Void .ctor(TSD.DOCS.AdminCategoryService.ListOrganizations.IListOrganizationRepository, TSD.DOCS.AdminCategoryService.ListOrganizations.ListOrganizationManager)'.

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.Extras.DynamicProxy.RegistrationExtensions.<>c__DisplayClass8_03.<EnableInterfaceInterceptors>b__1(ResolveRequestContext ctx, 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.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)
2024-10-28 10:41:19.323 +07:00 [ERR] ---------- Exception Data ----------
ActivatorChain = TSD.DOCS.AdminCategoryService.ListOrganizations.ListOrganizationController -> TSD.DOCS.AdminCategoryService.ListOrganizations.ListOrganizationsAppService

  • Steps to reproduce the issue: I created a DDD principle to manage our categories, use Abp Suite to generate code, I also selected the "Customizable code" option, just use the generated C# code without modify anything.
    After that, I import the project into AdministrationService project.
    I have tested in Swagger works well but when calling from js function, got the issue above.


10 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Cannot resolve parameter 'TSD.DOCS.AdminCategoryService.ListOrganizations.IListOrganizationRepository listOrganizationRepository' of

    Have you depended on the EF Core module?

    Please share the code of implementation code of IListOrganizationRepository

    Thanks.

  • User Avatar
    0
    duongdangquoc@gmail.com created

    Because I use "Customizable Code" option so I have two files:
    EfCoreListOrganizationRepository.cs

    public class EfCoreListOrganizationRepositoryBase : EfCoreRepository<IAdminCategoryServiceDbContext, ListOrganization, long>
    {
        public EfCoreListOrganizationRepositoryBase(IDbContextProvider<IAdminCategoryServiceDbContext> dbContextProvider)
            : base(dbContextProvider)
        {
    
        }
    
        public virtual async Task DeleteAllAsync(
            string? filterText = null,
                        long? nodeIdMin = null,
            long? nodeIdMax = null,
            string? orgName = null,
            string? orgShortcut = null,
            long? orgNodeIdMin = null,
            long? orgNodeIdMax = null,
            int? orgOrderMin = null,
            int? orgOrderMax = null,
            string? orgMap = null,
            string? dataOwner = null,
            short? statusMin = null,
            short? statusMax = null,
            string? textSearch = null,
            Guid? guidId = null,
            string? code = null,
            string? emailAddress = null,
            string? phoneNumber = null,
            string? address = null,
            string? cityId = null,
            string? districtId = null,
            short? portalOrgTypeMin = null,
            short? portalOrgTypeMax = null,
            short? fromSourceTypeMin = null,
            short? fromSourceTypeMax = null,
            short? isRegisterPortalMin = null,
            short? isRegisterPortalMax = null,
            Guid? portalGuidId = null,
            CancellationToken cancellationToken = default)
        {
    
            var query = await GetQueryableAsync();
    
            query = ApplyFilter(query, filterText, nodeIdMin, nodeIdMax, orgName, orgShortcut, orgNodeIdMin, orgNodeIdMax, orgOrderMin, orgOrderMax, orgMap, dataOwner, statusMin, statusMax, textSearch, guidId, code, emailAddress, phoneNumber, address, cityId, districtId, portalOrgTypeMin, portalOrgTypeMax, fromSourceTypeMin, fromSourceTypeMax, isRegisterPortalMin, isRegisterPortalMax, portalGuidId);
    
            var ids = query.Select(x => x.Id);
            await DeleteManyAsync(ids, cancellationToken: GetCancellationToken(cancellationToken));
        }
    
        public virtual async Task<List<ListOrganization>> GetListAsync(
            string? filterText = null,
            long? nodeIdMin = null,
            long? nodeIdMax = null,
            string? orgName = null,
            string? orgShortcut = null,
            long? orgNodeIdMin = null,
            long? orgNodeIdMax = null,
            int? orgOrderMin = null,
            int? orgOrderMax = null,
            string? orgMap = null,
            string? dataOwner = null,
            short? statusMin = null,
            short? statusMax = null,
            string? textSearch = null,
            Guid? guidId = null,
            string? code = null,
            string? emailAddress = null,
            string? phoneNumber = null,
            string? address = null,
            string? cityId = null,
            string? districtId = null,
            short? portalOrgTypeMin = null,
            short? portalOrgTypeMax = null,
            short? fromSourceTypeMin = null,
            short? fromSourceTypeMax = null,
            short? isRegisterPortalMin = null,
            short? isRegisterPortalMax = null,
            Guid? portalGuidId = null,
            string? sorting = null,
            int maxResultCount = int.MaxValue,
            int skipCount = 0,
            CancellationToken cancellationToken = default)
        {
            var query = ApplyFilter((await GetQueryableAsync()), filterText, nodeIdMin, nodeIdMax, orgName, orgShortcut, orgNodeIdMin, orgNodeIdMax, orgOrderMin, orgOrderMax, orgMap, dataOwner, statusMin, statusMax, textSearch, guidId, code, emailAddress, phoneNumber, address, cityId, districtId, portalOrgTypeMin, portalOrgTypeMax, fromSourceTypeMin, fromSourceTypeMax, isRegisterPortalMin, isRegisterPortalMax, portalGuidId);
            query = query.OrderBy(string.IsNullOrWhiteSpace(sorting) ? ListOrganizationConsts.GetDefaultSorting(false) : sorting);
            return await query.PageBy(skipCount, maxResultCount).ToListAsync(cancellationToken);
        }
    
        public virtual async Task<long> GetCountAsync(
            string? filterText = null,
            long? nodeIdMin = null,
            long? nodeIdMax = null,
            string? orgName = null,
            string? orgShortcut = null,
            long? orgNodeIdMin = null,
            long? orgNodeIdMax = null,
            int? orgOrderMin = null,
            int? orgOrderMax = null,
            string? orgMap = null,
            string? dataOwner = null,
            short? statusMin = null,
            short? statusMax = null,
            string? textSearch = null,
            Guid? guidId = null,
            string? code = null,
            string? emailAddress = null,
            string? phoneNumber = null,
            string? address = null,
            string? cityId = null,
            string? districtId = null,
            short? portalOrgTypeMin = null,
            short? portalOrgTypeMax = null,
            short? fromSourceTypeMin = null,
            short? fromSourceTypeMax = null,
            short? isRegisterPortalMin = null,
            short? isRegisterPortalMax = null,
            Guid? portalGuidId = null,
            CancellationToken cancellationToken = default)
        {
            var query = ApplyFilter((await GetDbSetAsync()), filterText, nodeIdMin, nodeIdMax, orgName, orgShortcut, orgNodeIdMin, orgNodeIdMax, orgOrderMin, orgOrderMax, orgMap, dataOwner, statusMin, statusMax, textSearch, guidId, code, emailAddress, phoneNumber, address, cityId, districtId, portalOrgTypeMin, portalOrgTypeMax, fromSourceTypeMin, fromSourceTypeMax, isRegisterPortalMin, isRegisterPortalMax, portalGuidId);
            return await query.LongCountAsync(GetCancellationToken(cancellationToken));
        }
    
        protected virtual IQueryable<ListOrganization> ApplyFilter(
            IQueryable<ListOrganization> query,
            string? filterText = null,
            long? nodeIdMin = null,
            long? nodeIdMax = null,
            string? orgName = null,
            string? orgShortcut = null,
            long? orgNodeIdMin = null,
            long? orgNodeIdMax = null,
            int? orgOrderMin = null,
            int? orgOrderMax = null,
            string? orgMap = null,
            string? dataOwner = null,
            short? statusMin = null,
            short? statusMax = null,
            string? textSearch = null,
            Guid? guidId = null,
            string? code = null,
            string? emailAddress = null,
            string? phoneNumber = null,
            string? address = null,
            string? cityId = null,
            string? districtId = null,
            short? portalOrgTypeMin = null,
            short? portalOrgTypeMax = null,
            short? fromSourceTypeMin = null,
            short? fromSourceTypeMax = null,
            short? isRegisterPortalMin = null,
            short? isRegisterPortalMax = null,
            Guid? portalGuidId = null)
        {
            return query
                    .WhereIf(!string.IsNullOrWhiteSpace(filterText), e => e.OrgName!.Contains(filterText!) || e.OrgShortcut!.Contains(filterText!) || e.OrgMap!.Contains(filterText!) || e.DataOwner!.Contains(filterText!) || e.TextSearch!.Contains(filterText!) || e.Code!.Contains(filterText!) || e.EmailAddress!.Contains(filterText!) || e.PhoneNumber!.Contains(filterText!) || e.Address!.Contains(filterText!) || e.CityId!.Contains(filterText!) || e.DistrictId!.Contains(filterText!))
                    .WhereIf(nodeIdMin.HasValue, e => e.NodeId >= nodeIdMin!.Value)
                    .WhereIf(nodeIdMax.HasValue, e => e.NodeId <= nodeIdMax!.Value)
                    .WhereIf(!string.IsNullOrWhiteSpace(orgName), e => e.OrgName.Contains(orgName))
                    .WhereIf(!string.IsNullOrWhiteSpace(orgShortcut), e => e.OrgShortcut.Contains(orgShortcut))
                    .WhereIf(orgNodeIdMin.HasValue, e => e.OrgNodeId >= orgNodeIdMin!.Value)
                    .WhereIf(orgNodeIdMax.HasValue, e => e.OrgNodeId <= orgNodeIdMax!.Value)
                    .WhereIf(orgOrderMin.HasValue, e => e.OrgOrder >= orgOrderMin!.Value)
                    .WhereIf(orgOrderMax.HasValue, e => e.OrgOrder <= orgOrderMax!.Value)
                    .WhereIf(!string.IsNullOrWhiteSpace(orgMap), e => e.OrgMap.Contains(orgMap))
                    .WhereIf(!string.IsNullOrWhiteSpace(dataOwner), e => e.DataOwner.Contains(dataOwner))
                    .WhereIf(statusMin.HasValue, e => e.Status >= statusMin!.Value)
                    .WhereIf(statusMax.HasValue, e => e.Status <= statusMax!.Value)
                    .WhereIf(!string.IsNullOrWhiteSpace(textSearch), e => e.TextSearch.Contains(textSearch))
                    .WhereIf(guidId.HasValue, e => e.GuidId == guidId)
                    .WhereIf(!string.IsNullOrWhiteSpace(code), e => e.Code.Contains(code))
                    .WhereIf(!string.IsNullOrWhiteSpace(emailAddress), e => e.EmailAddress.Contains(emailAddress))
                    .WhereIf(!string.IsNullOrWhiteSpace(phoneNumber), e => e.PhoneNumber.Contains(phoneNumber))
                    .WhereIf(!string.IsNullOrWhiteSpace(address), e => e.Address.Contains(address))
                    .WhereIf(!string.IsNullOrWhiteSpace(cityId), e => e.CityId.Contains(cityId))
                    .WhereIf(!string.IsNullOrWhiteSpace(districtId), e => e.DistrictId.Contains(districtId))
                    .WhereIf(portalOrgTypeMin.HasValue, e => e.PortalOrgType >= portalOrgTypeMin!.Value)
                    .WhereIf(portalOrgTypeMax.HasValue, e => e.PortalOrgType <= portalOrgTypeMax!.Value)
                    .WhereIf(fromSourceTypeMin.HasValue, e => e.FromSourceType >= fromSourceTypeMin!.Value)
                    .WhereIf(fromSourceTypeMax.HasValue, e => e.FromSourceType <= fromSourceTypeMax!.Value)
                    .WhereIf(isRegisterPortalMin.HasValue, e => e.IsRegisterPortal >= isRegisterPortalMin!.Value)
                    .WhereIf(isRegisterPortalMax.HasValue, e => e.IsRegisterPortal <= isRegisterPortalMax!.Value)
                    .WhereIf(portalGuidId.HasValue, e => e.PortalGuidId == portalGuidId);
        }
    }
    

    EfCoreListOrganizationRepository.Extended.cs

    public class EfCoreListOrganizationRepository : EfCoreListOrganizationRepositoryBase, IListOrganizationRepository
    {
        public EfCoreListOrganizationRepository(IDbContextProvider<IAdminCategoryServiceDbContext> dbContextProvider)
            : base(dbContextProvider)
        {
        }
    }
    

    This is dependencies in the AdministrationService project
    image.png

  • User Avatar
    0
    duongdangquoc@gmail.com created

    If needed, I can share all solutions with you by adding you to my Github repo.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer
  • User Avatar
    0
    duongdangquoc@gmail.com created

    I just sent the invitation, please check your email.
    Main project is TSD.DOCS.AdminCategoryService in \services\admin\category

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I have started running your project.

    I have tested in Swagger works well but when calling from js function, got the issue above.

    Can you share the steps to show the problem?

    image.png

    Thanks

  • User Avatar
    0
    duongdangquoc@gmail.com created

    I run in Swagger:
    image.png

    This is I have tried in UI:
    image.png

  • User Avatar
    1
    maliming created
    Support Team Fullstack Developer

    The web project is a pure UI project, so you can't add EF core and app service modules to it.

    Please change it as follows:

    image.png

  • User Avatar
    0
    duongdangquoc@gmail.com created

    It works as expect. Thank you so much.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Great

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on May 28, 2025, 08:51