• Abp 构造注入服务接口后运行报错 Host terminated unexpectedly!


    1. 使用场景,在内部创建一个接口,由于这个接口不对外提供任何的服务,只是内部逻辑使用,故不继承IApplicationService 接口和实现ApplicationService

    1.1 接口实现类只是简单实现了接口方法,并没有继承 ApplicationService

    2. 使用的时候是通过构造函数进行注入使用,例如

    2.1 运行起来就直接报错了

    1. Host terminated unexpectedly!
    2. Volo.Abp.AbpInitializationException: An error occurred during the initialize Volo.Abp.Modularity.OnApplicationInitializationModuleLifecycleContributor phase of the module Volo.Abp.BackgroundWorkers.Quartz.AbpBackgroundWorkersQuartzModule, Volo.Abp.BackgroundWorkers.Quartz, Version=5.2.2.0, Culture=neutral, PublicKeyToken=null: An exception was thrown while activating λ:Volo.Abp.BackgroundWorkers.Quartz.IQuartzBackgroundWorker[] -> ZZJCApiOrDeviceModule.Domain.Worker.PlcWorker.. See the inner exception for details.
    3. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while activating λ:Volo.Abp.BackgroundWorkers.Quartz.IQuartzBackgroundWorker[] -> ZZJCApiOrDeviceModule.Domain.Worker.PlcWorker.
    4. ---> Autofac.Core.DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'ZZJCApiOrDeviceModule.Domain.Worker.PlcWorker' can be invoked with the available services and parameters:
    5. Cannot resolve parameter 'ZZJCApiOrDeviceModule.Application.PlcServices.plcAppService plcAppService' of constructor 'Void .ctor(Volo.Abp.EventBus.Local.ILocalEventBus, ZZJCApiOrDeviceModule.Application.PlcServices.plcAppService)'.
    6. at Autofac.Core.Activators.Reflection.ReflectionActivator.GetAllBindings(ConstructorBinder[] availableConstructors, IComponentContext context, IEnumerable`1 parameters)
    7. at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
    8. at Autofac.Core.Activators.Reflection.ReflectionActivator.<ConfigurePipeline>b__11_0(ResolveRequestContext ctxt, Action`1 next)
    9. at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action`1 next) at Autofac.Builder.RegistrationBuilder`3.<>c__DisplayClass41_0.<PropertiesAutowired>b__0(ResolveRequestContext ctxt, Action`1 next)
    10. at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
    11. --- End of inner exception stack trace ---
    12. at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
    13. at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
    14. at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action`1 next)
    15. at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request)
    16. at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request)
    17. at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
    18. at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
    19. at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
    20. at Volo.Abp.BackgroundWorkers.Quartz.AbpBackgroundWorkersQuartzModule.OnApplicationInitializationAsync(ApplicationInitializationContext context)
    21. at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task)
    22. at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
    23. --- End of stack trace from previous location ---
    24. at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
    25. --- End of stack trace from previous location ---
    26. at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task)
    27. at Nito.AsyncEx.AsyncContext.Run(Func`1 action)
    28. at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context)
    29. --- End of inner exception stack trace ---
    30. at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context)
    31. at Volo.Abp.AbpApplicationBase.InitializeModules()
    32. at Microsoft.AspNetCore.Builder.AbpApplicationBuilderExtensions.InitializeApplication(IApplicationBuilder app)
    33. at WMS.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env,
    34. at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
    35. at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    36. at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
    37. at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
    38. at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
    39. at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
    40. at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

     2.3 解决方法,可能是没有继承ApplicationService,它无法进行初始化,导致注入的时候,构造函数无法正常解析。所以直接在接口实现类加入一个 生命周期函数 ITransientDependency 来进行初始化,就正常了

  • 相关阅读:
    linux删除 buff/cache缓存
    CANdelaStudio-从入门到深入到实践目录
    [问题解决] no CUDA-capable device is detected
    拼多多众多 API 接口皆可使用
    Total Software Deployment为您的企业网络管理软件部署
    python实现提取文件名某个字符串并新建文件夹保存,判断两个矩形是否相交或重合
    js常用的数组处理方法
    低代码平台那些事儿
    2022年5大直播趋势
    【Hadoop---03】Hadoop环境配置「安装虚拟机、安装CentOS操作系统 | 虚拟机的网络配置 | 远程登陆 | 分布式集群」
  • 原文地址:https://blog.csdn.net/weixin_39237340/article/details/126321928