Invocation of BackgroundJob.Enqueue()


#1

What’s the difference in the invocation of this BackgroundJob.Enqueue(() => x.MyMethod()) vs. BackgroundJob.Enqueue< IInterface >(x => x.MyMethod()). Specially, why the first option would throw Hangfire Autofac.Core.Registration.ComponentNotRegisteredException but the 2nd one would work with no problem?

Thanks!


#2

The first one uses a concrete type to invoke the method on, which is likely not registered in service container (AsSelf() or something). The second one explicitly specifies that the method is invoked on the interface, which can be correctly resolved.

It is not recommended to use the non-generic method exactly because of this.