I’m working on integrating Hangfire into our product using Autofac as an IoC container, and wish to use the InstancePerLifetimeScope(). However, when I register types using the builder, I get the following exception:
Method not found: 'Autofac.Builder.IRegistrationBuilder`3<!0,!1,!2> Autofac.Builder.IRegistrationBuilder`3.InstancePerMatchingLifetimeScope(System.Object)'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MissingMethodException: Method not found: 'Autofac.Builder.IRegistrationBuilder`3<!0,!1,!2> Autofac.Builder.IRegistrationBuilder`3.InstancePerMatchingLifetimeScope(System.Object)'.
Source Error:
Line 36:
Line 37: // register test job class
Line 38: builder.RegisterType<HangfireTest>()
Line 39: .As<IHangfireTest>()
Line 40: .InstancePerBackgroundJob();
I’m trying to figure out where I’m going wrong. If I register the type as InstancePerLifetimeScope(), everything works, and the job resolves the type correctly and executes correctly:
builder.RegisterType<HangfireTest>()
.As<IHangfireTest>()
.InstancePerLifetimeScope();
Any suggestions on what I should be looking for? Is there additional configuration required to use the InstancePerBackgroundJob scope? Is this potentially a bug in the beta version?
I’m using the following packages:
Autofac 3.5.2
HangFire.Core 1.5.0-beta2
HangFire.SqlServer 1.5.0-beta2
HangFire.Autofac 1.2.0-beta1