1. 使用场景,在内部创建一个接口,由于这个接口不对外提供任何的服务,只是内部逻辑使用,故不继承IApplicationService 接口和实现ApplicationService
1.1 接口实现类只是简单实现了接口方法,并没有继承 ApplicationService
2. 使用的时候是通过构造函数进行注入使用,例如
2.1 运行起来就直接报错了
Host terminated unexpectedly!
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.
---> Autofac.Core.DependencyResolutionException: An exception was thrown while activating λ:Volo.Abp.BackgroundWorkers.Quartz.IQuartzBackgroundWorker[] -> ZZJCApiOrDeviceModule.Domain.Worker.PlcWorker.
---> 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:
Cannot resolve parameter 'ZZJCApiOrDeviceModule.Application.PlcServices.plcAppService plcAppService' of constructor 'Void .ctor(Volo.Abp.EventBus.Local.ILocalEventBus, ZZJCApiOrDeviceModule.Application.PlcServices.plcAppService)'.
at Autofac.Core.Activators.Reflection.ReflectionActivator.GetAllBindings(ConstructorBinder[] availableConstructors, IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Activators.Reflection.ReflectionActivator.<ConfigurePipeline>b__11_0(ResolveRequestContext ctxt, Action`1 next)
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)
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.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action`1 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, IEnumerable`1 parameters, Object& instance)
at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Volo.Abp.BackgroundWorkers.Quartz.AbpBackgroundWorkersQuartzModule.OnApplicationInitializationAsync(ApplicationInitializationContext context)
at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
at Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task)
at Nito.AsyncEx.AsyncContext.Run(Func`1 action)
at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context)
--- End of inner exception stack trace ---
at Volo.Abp.Modularity.ModuleManager.InitializeModules(ApplicationInitializationContext context)
at Volo.Abp.AbpApplicationBase.InitializeModules()
at Microsoft.AspNetCore.Builder.AbpApplicationBuilderExtensions.InitializeApplication(IApplicationBuilder app)
at WMS.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env,
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
2.3 解决方法,可能是没有继承ApplicationService,它无法进行初始化,导致注入的时候,构造函数无法正常解析。所以直接在接口实现类加入一个 生命周期函数 ITransientDependency 来进行初始化,就正常了