I recently learned about Hangfire but had no luck with it so far. My project uses autofac so I’ve added HangFire.1.4.3 & HangFire.Autofac.1.1.0 nuget packages to my project. Followed by documentation I’ve created Startup class and registered Hangfire there
public void Configuration(IAppBuilder app)
{
GlobalConfiguration.Configuration
.UseSqlServerStorage("NavigatorConnectionString");
app.UseHangfireDashboard();
app.UseHangfireServer();
}
After that I’ve updated WebApiConfig and registered my Autofac container in Hangfire
private static void RegisterDependencies(HttpConfiguration config)
{
var builder = new ContainerBuilder();
...
var container = builder.Build();
...
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
Hangfire.GlobalConfiguration.Configuration.UseAutofacActivator(container);
}
When I try to run Hangfire job like
IObject someObject = MyObject();
var jobId = BackgroundJob.Enqueue<IMyInterface>(x
=> x.MyMethod(someObject));
I get the following error
System.InvalidOperationException
The typeMyNamespace.IMyInterface
does not contain a method with signatureMyMethod(IObject
1)`
at Hangfire.Storage.InvocationData.Deserialize()
UPDATE: I’ve figured out that resolve doesn’t work when interface has generic declaration. Sort of
public TResult MyMethod(IObject query)
What can be the issue?