I’m calling simple method using Fire and Forget but it giving me this error.
var res = BackgroundJob.Enqueue<IGsddRepository>( x => x.GetDrugDescription(drugId));
I let my constructor handle the instantiation of the interface and then pass the instance to Hangfire.
That said, you might want to take a look at:
Hangfire.GlobalConfiguration.Configuration.UseAutofacActivator(this.AutofacDependencyInjectionContainer);
Which is called in the ConfigureServices method of your StartUp.cs.
Thanks @wildough57 for the response I will check and let you know.
// Job ID: #22
using erw.DatabaseServices;
var gsddRepository = Activate<GsddRepository>();
await gsddRepository.GetDrugDescription(1478474);
No parameterless constructor defined for this object.
System.MissingMethodException: No parameterless constructor defined for this object.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Hangfire.JobActivator.ActivateJob(Type jobType)
at Hangfire.JobActivator.SimpleJobActivatorScope.Resolve(Type type)
at Hangfire.Server.CoreBackgroundJobPerformer.Perform(PerformContext context)
at Hangfire.Server.BackgroundJobPerformer.<>c__DisplayClass9_0.b__0()
at Hangfire.Server.BackgroundJobPerformer.InvokePerformFilter(IServerFilter filter, PerformingContext preContext, Func1 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’m getting this error @wildough57
In startup.cs I wrote these lines
var builder = new ContainerBuilder();
// register your classes and expose their interfaces - shared
builder.RegisterModule(new StandardModule());
//builder.Build();
Hangfire.GlobalConfiguration.Configuration.UseAutofacActivator(builder.Build());
I don’t know about your code but I do my builder.Build() in my StartUp’s Confiigure method.
As I suggested, the call to UseAutofacActivator() goes in the ConfigureServices method.
And I don’t use Activate(). I’m not familiar with it.
Best of luck.
Will