abpframework / abp

Open Source Web Application Framework for ASP.NET Core. Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET and the ASP.NET Core platforms. Provides the fundamental infrastructure, production-ready startup templates, application modules, UI themes, tooling, guides and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.31k stars 3.32k forks source link

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

Closed BekAllaev closed 2 weeks ago

BekAllaev commented 2 weeks ago

Is there an existing issue for this?

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

maliming commented 2 weeks ago

hi

You need to add C# Client Proxies for your Application's api because Blazor wasm is a separate app.

https://docs.abp.io/en/abp/latest/UI/Blazor/Overall#dynamic-c-client-proxies https://docs.abp.io/en/abp/latest/API/Dynamic-CSharp-API-Clients https://docs.abp.io/en/abp/latest/API/Static-CSharp-API-Clients

BekAllaev commented 2 weeks ago

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

yuannisha commented 2 weeks ago

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 commented 2 weeks ago

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

yuannisha commented 2 weeks ago

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 commented 2 weeks ago

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

it appears when I use the API for my application service

BekAllaev commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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!