Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service that was registered in application layer not injecting in Blazor class #19638

Closed
1 task done
BekAllaev opened this issue Apr 28, 2024 · 11 comments
Closed
1 task done

Comments

@BekAllaev
Copy link

BekAllaev commented Apr 28, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Description

I have interface IStasticsRecalculator defined in to Application.Contracts project and its implementation - StasticsRecalculator in Application project. In module class of Application project I register it like this:

context.Services.AddTransient<IStasticsRecalculator, StasticsRecalculator>();

After that I inject IStasticsRecalculator into class in Blazor project and get this error:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: An exception was thrown while activating OMSBlazor.Blazor.Pages.Order.Create.CreateView -> OMSBlazor.Blazor.Pages.Order.Create.CreateViewModel.
Autofac.Core.DependencyResolutionException: An exception was thrown while activating OMSBlazor.Blazor.Pages.Order.Create.CreateView -> OMSBlazor.Blazor.Pages.Order.Create.CreateViewModel.
 ---> Autofac.Core.DependencyResolutionException: None of the constructors found on type 'OMSBlazor.Blazor.Pages.Order.Create.CreateViewModel' can be invoked with the available services and parameters:
Cannot resolve parameter 'OMSBlazor.Interfaces.Services.IStasticsRecalculator stasticsRecalculator' of constructor 'Void .ctor(OMSBlazor.Interfaces.ApplicationServices.IEmployeeApplicationService, OMSBlazor.Interfaces.ApplicationServices.IOrderApplicationService, OMSBlazor.Interfaces.ApplicationServices.IProductApplicationService, OMSBlazor.Interfaces.ApplicationServices.ICustomerApplcationService, OMSBlazor.Interfaces.Services.IStasticsRecalculator)'.

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, Action`1 next)
   at Autofac.Core.Resolving.Middleware.DelegateMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext context)
   at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext context)
   at Autofac.Builder.RegistrationBuilder`3.<>c__DisplayClass41_0[[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Autofac.Builder.ConcreteReflectionActivatorData, Autofac, Version=7.1.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da],[Autofac.Builder.SingleRegistrationStyle, Autofac, Version=7.1.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da]].<PropertiesAutowired>b__0(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Middleware.DelegateMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext context)
   at Autofac.Builder.RegistrationBuilder`3.<>c__DisplayClass39_0[[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Autofac.Builder.ConcreteReflectionActivatorData, Autofac, Version=7.1.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da],[Autofac.Builder.SingleRegistrationStyle, Autofac, Version=7.1.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da]].<OnActivated>b__0(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Middleware.CoreEventMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext context)
   at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   --- End of inner exception stack trace ---
   at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 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, Action`1 next)
   at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext context)
   at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext context)
   at Autofac.Core.Resolving.Middleware.ScopeSelectionMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext context)
   at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action`1 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.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
   at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters)
   at Autofac.ResolutionExtensions.ResolveOptional(IComponentContext context, Type serviceType, IEnumerable`1 parameters)
   at Autofac.ResolutionExtensions.ResolveOptional(IComponentContext context, Type serviceType)
   at Autofac.Extensions.DependencyInjection.AutofacServiceProvider.GetService(Type serviceType)
   at Blazorise.ComponentActivator.CreateInstance(Type componentType)
   at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider serviceProvider, Type componentType, IComponentRenderMode callerSpecifiedRenderMode, Nullable`1 parentComponentId)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateChildComponentOnFrame(RenderTreeFrame[] frames, Int32 frameIndex, Int32 parentComponentId)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& diffContext, Int32 frameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& diffContext, Int32 frameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()

Reproduction Steps

No response

Expected behavior

No response

Actual behavior

No response

Regression?

No response

Known Workarounds

No response

Version

8.0.1

User Interface

Blazor

Database Provider

EF Core (Default)

Tiered or separate authentication server

None (Default)

Operation System

Windows (Default)

Other information

No response

@BekAllaev BekAllaev added the bug label Apr 28, 2024
@maliming
Copy link
Member

@BekAllaev
Copy link
Author

Oh I understand what is the reason of the problem, thanks a lot. So I just need to inherit my IStasticsRecalculator from IRemoteService

@yuannisha
Copy link

Oh I understand what is the reason of the problem, thanks a lot. So I just need to inherit my IStasticsRecalculator from IRemoteService

hello my dear bro,I have the same problem too,but it’s unuseful afterl I do the same step liek you that inheriting my IXXXService from IRemoteService,do you know why? Or I misunderstand your opeartion?Could you please tell me how you resolve this problem?

@BekAllaev
Copy link
Author

Hello, @yuannisha. Can you explain please - what error you are getting?

@yuannisha
Copy link

Hello, @yuannisha. Can you explain please - what error you are getting?

An exception was thrown while activating Wz.ReservingSystem.CustomUserAppservice.CustomUserAppservices.
Autofac.Core.DependencyResolutionException: An exception was thrown while activating Wz.ReservingSystem.CustomUserAppservice.CustomUserAppservices.
---> Autofac.Core.DependencyResolutionException: None of the constructors found on type 'Wz.ReservingSystem.CustomUserAppservice.CustomUserAppservices' can be invoked with the available services and parameters:
Cannot resolve parameter 'Microsoft.AspNetCore.Identity.SignInManager1[Wz.ReservingSystem.Users.User] signInManager' of constructor 'Void .ctor(Volo.Abp.Domain.Repositories.IRepository2[Wz.ReservingSyste
m.Users.User,System.Guid], Volo.Abp.ObjectMapping.IObjectMapper, Volo.Abp.Domain.Repositories.IRepository2[Wz.ReservingSystem.ReservingOperation.ReservingInformation,System.Guid], Microsoft.AspNetCore.Identity.SignInManager1[Wz.ReservingSystem.Users.User])'.
This is my error

@yuannisha
Copy link

Hello, @yuannisha. Can you explain please - what error you are getting?

it appears when I use the API for my application service

@BekAllaev
Copy link
Author

So ABP cannot resolve SignInManager. I haven't found anything about injecting SignInManager into application service but I have found this article from ABP that explain how to implement custom SignInManager - https://docs.abp.io/en/abp/2.9/How-To/Customize-SignIn-Manager. I wish that will help somehow but I think that IRemoteService interface won't help you

@yuannisha
Copy link

So ABP cannot resolve SignInManager. I haven't found anything about injecting SignInManager into application service but I have found this article from ABP that explain how to implement custom SignInManager - https://docs.abp.io/en/abp/2.9/How-To/Customize-SignIn-Manager. I wish that will help somehow but I think that IRemoteService interface won't help you

I don't think the issue lies with using SignInManager, but rather with the error message: Autofac.Core.DependencyResolutionException: None of the constructors found on type 'Wz.ReservingSystem.CustomUserAppservice.CustomUserAppservices' can be invoked with the available services and parameters. I am using abp version 8.1, and this problem occurs after I finish the application service and expose it as an API. Whenever I use the API, this error occurs. It seems to be related to automatic dependency injection. I never encountered these issues when using older versions of abp, but after using versions 7 and above, this problem keeps happening. I am unsure how to resolve this.

@yuannisha
Copy link

Autofac.Core.DependencyResolutionException: None of the constructors found on type

The accurate description is as follows: I have not modified the framework source code. I have simply added entities, mapping tables, service interfaces, implemented service interfaces, and exposed the services as APIs. After completing these steps, I began testing my API. However, when making API requests, I encountered this issue. Do you know what might be causing this problem? Could you please help me resolve this issue? I am a bit anxious to fix this problem. Thank you very much!

@BekAllaev
Copy link
Author

Can you please try to remove SignInManager from the parameters of the constructor of CustomUserAppservices and try to call some methods of CustomerUserAppservices and say me is it working or not? @yuannisha

@yuannisha
Copy link

Can you please try to remove SignInManager from the parameters of the constructor of CustomUserAppservices and try to call some methods of CustomerUserAppservices and say me is it working or not? @yuannisha

Oh thanks you a lot,it seems like being resolved with your suggestion,thanks!

@maliming maliming removed the bug label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants