Hangfire, Autofac and WebApi

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)

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);

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

The type MyNamespace.IMyInterface does not contain a method with signature MyMethod(IObject1)`
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?

The issue is in hangfire way of work. It serializes parameters and in case of generics can’t desirialize it back. The workaround is create a mediator that can be easily serialized/desirialized and run the code you need.