简体   繁体   中英

Service 'Abp.Quartz.IQuartzScheduleJobManager' which was not registered

I have downloaded .NET Core + Vue template for ASP.NET Boilerplate (v3.7.0).

I added:

[DependsOn(typeof(AbpAutoMapperModule), typeof(AbpQuartzModule))]
public class MyAbpQuartzModule : AbpModule
{
  public override void Initialize()
  {
    IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
  }
}
  • MyAbpQuartzController.cs in xxx.Web.Host project:
public class MyAbpQuartzController : AbpController
{
  private readonly IQuartzScheduleJobManager _jobManager;

  public MyAbpQuartzController(IQuartzScheduleJobManager jobManager)
  {
      _jobManager = jobManager;
  }

  public async Task<ActionResult> ScheduleJobWithTask()
  {
      await _jobManager.ScheduleAsync<MyLogJob>(
          job =>
          {
              job.WithIdentity("MyLogJobIdentity", "MyGroup")
                  .WithDescription("A job to simply write logs.");
          },
          trigger =>
          {
              trigger.StartNow()
                  .WithSimpleSchedule(schedule =>
                  {
                      schedule.RepeatForever()
                          .WithIntervalInSeconds(5)
                          .Build();
                  });
          });

      return Content("OK, scheduled!");
  }

  public ContentResult TestMyAbpQuartz(string message = "")
  {
      return Content("OK, scheduled!");
  }
}

I debugged the xxx.Web.Host project, but it didn't work.

The http://localhost:21021/MyAbpQuartz/TestMyAbpQuartz page returned:
"This page isn't working localhost is currently unable to handle this request. HTTP ERROR 500"

I think that QuartzScheduleJobManager didn't register successfully.

So, what should I do?

Part of error message in Web.Host/App_Data/log.txt :

ERROR 2018-06-08 19:19:04,161 [5    ] Mvc.ExceptionHandling.AbpExceptionFilter - Can't create component 'MyNetCoreWithVueProject.Web.Host.Controllers.MyAbpQuartzController' as it has dependencies to be satisfied.

'MyNetCoreWithVueProject.Web.Host.Controllers.MyAbpQuartzController' is waiting for the following dependencies:
- Service 'Abp.Quartz.IQuartzScheduleJobManager' which was not registered.

Castle.MicroKernel.Handlers.HandlerException: Can't create component 'MyNetCoreWithVueProject.Web.Host.Controllers.MyAbpQuartzController' as it has dependencies to be satisfied.

'MyNetCoreWithVueProject.Web.Host.Controllers.MyAbpQuartzController' is waiting for the following dependencies:
- Service 'Abp.Quartz.IQuartzScheduleJobManager' which was not registered.

   at Castle.MicroKernel.Handlers.DefaultHandler.AssertNotWaitingForDependency()
   at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
   at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
   at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy)
   at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy)
   at Castle.Windsor.MsDependencyInjection.ScopedWindsorServiceProvider.GetServiceInternal(Type serviceType, Boolean isOptional) in D:\Github\castle-windsor-ms-adapter\src\Castle.Windsor.MsDependencyInjection\ScopedWindsorServiceProvider.cs:line 55
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextExceptionFilterAsync>d__23.MoveNext()
INFO  2018-06-08 19:19:04,967 [5    ] ore.Mvc.Internal.ControllerActionInvoker - Executed action MyNetCoreWithVueProject.Web.Host.Controllers.MyAbpQuartzController.TestMyAbpQuartz (MyNetCoreWithVueProject.Web.Host) in 833.6801ms
ERROR 2018-06-08 19:19:05,059 [5    ] Microsoft.AspNetCore.Server.Kestrel      - Connection id "0HLED66DNH26L", Request id "0HLED66DNH26L:00000004": An unhandled exception was thrown by the application.
Castle.MicroKernel.Handlers.HandlerException: Can't create component 'MyNetCoreWithVueProject.Web.Host.Controllers.MyAbpQuartzController' as it has dependencies to be satisfied.

If you want to register a specific class that does not fit into the conventional registration rules. ASP.NET Boilerplate provides the ITransientDependency, the IPerWebRequestDependency and the ISingletonDependency interfaces as a shortcut.

public interface IQuartzScheduleJobManager
{
    //...
}

public class QuartzScheduleJobManager: IQuartzScheduleJobManager, ITransientDependency
{
    //...
}

IQuartzScheduleJobManager should be registered by AbpQuartzModule .

I see that you already have [DependsOn(typeof(AbpQuartzModule))] on MyAbpQuartzModule .

Add [DependsOn(typeof(MyAbpQuartzModule))] to *WebHostModule :

[DependsOn(
    typeof(AbpProjectNameWebCoreModule),
    typeof(MyAbpQuartzModule))]
public class AbpProjectNameWebHostModule : AbpModule

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM