abp.io + hangfire issue A suitable constructor for type XXXX could not be located

491 views Asked by At

I'm just trying to run a background job with ABP.IO project and Hangfire (I have already made it with aspnetboilerplate without any issue)

Each time my recurringjob start it throw this error :

A suitable constructor for type 'AbpIo.TachePlan.ITachePlanifiee' could not be located.

For this test I just write an Interface in Contracts project

using System;
using System.Collections.Generic;
using System.Text;

namespace AbpIo.TachePlan
{
    public interface ITachePlanifiee
    {
        void Test();
    }
}

and the implementation in Application project

using System;
using System.Collections.Generic;
using System.Text;

    namespace AbpIo.TachePlan
    {
        public class TachePlanifiee : ITachePlanifiee
        {
           
            public TachePlanifiee()
            { }
    
            public void Test()
            {
                //Great job
            }
        }
    }

In the web project

public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
//default ABP.IO code
            app.UseHangfireDashboard();

            
            RecurringJob.AddOrUpdate<ITachePlanifiee>(x=> x.Test(), "*/15 * * * *"); 
        }

but result is

System.InvalidOperationException
A suitable constructor for type 'AbpIo.TachePlan.ITachePlanifiee' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.

System.InvalidOperationException: A suitable constructor for type 'AbpIo.TachePlan.ITachePlanifiee' 

could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.

   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type)
   at Hangfire.AspNetCore.AspNetCoreJobActivatorScope.Resolve(Type type)
   at Hangfire.Server.CoreBackgroundJobPerformer.Perform(PerformContext context)
   at Hangfire.Server.BackgroundJobPerformer.<>c__DisplayClass9_0.<PerformJobWithFilters>b__0()
   at Hangfire.Server.BackgroundJobPerformer.InvokePerformFilter(IServerFilter filter, PerformingContext preContext, Func`1 continuation)
   at Hangfire.Server.BackgroundJobPerformer.<>c__DisplayClass9_1.<PerformJobWithFilters>b__2()
   at Hangfire.Server.BackgroundJobPerformer.PerformJobWithFilters(PerformContext context, IEnumerable`1 filters)
   at Hangfire.Server.BackgroundJobPerformer.Perform(PerformContext context)
   at Hangfire.Server.Worker.PerformJob(BackgroundProcessContext context, IStorageConnection connection, String jobId)

I need help because I don't understant where is my mistake

Regards

1

There are 1 answers

0
seb49 On

Thank you for you comments, they help me.

So I found my mistake.

My interface didn't implement one of these interface

  • ITransientDependency
  • ISingletonDependency
  • IScopedDependency

https://docs.abp.io/en/abp/latest/Dependency-Injection

using Volo.Abp.DependencyInjection;

namespace AbpIo.TachePlan
{
    public interface ITachePlanifiee : ITransientDependency
    {
        void Test();
    }
}