Hi,
I’ve just started using HangFire. The jobs seem to work fine when I run it locally from IIS Express, but when I run it on my dev server I get errors that no parameterless constructor defined. I was using Simple Injector earlier but now I’ve moved to Autofac.
Here’s my startup class
` public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
ConfigureIoc(app);
ConfigureRoutes();
ConfigureHangfire(app);
ScheduleXeroMonitor();
}
public void ConfigureHangfire(IAppBuilder app)
{
var authList = new List<IDashboardAuthorizationFilter>
{
new ClaimsBasedAuthorizationFilter("role", "admin")
};
var options = new DashboardOptions
{
Authorization = authList,
AppPath = "/Manage"
};
app.UseHangfireDashboard("/hangfire", options);
app.UseHangfireServer();
}
public void ConfigureRoutes()
{
BundleTable.EnableOptimizations = true;
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
public void ConfigureIoc(IAppBuilder app)
{
var builder = DependencyRegistrar.RegisterClasses();
var container = builder.Build();
app.UseAutofacMiddleware(container);
app.UseAutofacMvc();
GlobalConfiguration.Configuration.UseAutofacActivator(container);
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Login"),
CookieSecure = CookieSecureOption.SameAsRequest,
});
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions()
{
AuthenticationType = DefaultAuthenticationTypes.ExternalBearer,
AuthenticationMode = AuthenticationMode.Passive
});
AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.Name;
}
public void ScheduleXeroMonitor()
{
var backGroundWorker = DependencyResolver.Current.GetService<IXeroBackGroundWorker>();
RecurringJob.AddOrUpdate("XeroPolling", () => backGroundWorker.PollJobs(), Cron.Minutely); //change the Cron to every 5 minutes
var emailWorker = DependencyResolver.Current.GetService<IEmailService>();
RecurringJob.AddOrUpdate("EmailPolling", () => emailWorker.SendQueuedEmails(), Cron.Minutely);//"*/10 * * * *"
}
}`
Here’s the static class where I register my classes
`public class DependencyRegistrar
{
public static ContainerBuilder RegisterClasses()
{
var builder = new ContainerBuilder();
builder.RegisterType().As().InstancePerLifetimeScope();
builder.RegisterType().As().InstancePerLifetimeScope();
builder.RegisterType().As().InstancePerLifetimeScope();
builder.RegisterControllers(Assembly.GetExecutingAssembly());
return builder;
}
}`
Can someone please tell me what I’m doing wrong.