We left Russia. We are against aggression and war with Ukraine. It is a tragedy for our nations, it is a nightmare

Hangfire with Unity

I inject the IBackgroundClient in my API Controllers and use OWIN Startup for iOC.

public static void RegisterTypes(IUnityContainer unityContainer)
            unityContainer.RegisterType<IBackgroundJobClient, BackgroundJobClient>(new PerResolveLifetimeManager());

Whenever i call my webapi i get the following error:

(HttpRequestMessage request)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()",
“innerException”: {
“message”: “An error has occurred.”,
“exceptionMessage”: "Resolution of the dependency failed, type = “EMMS.Leads.WebAPI.Controllers.LeadsController”, name = “(none)”.\r\nException occurred while: while resolving.\r\nException is: InvalidOperationException - The current type, Hangfire.JobStorage, is an abstract class and cannot be constructed. Are you missing a type mapping?\r\n-----------------------------------------------\r\nAt the time of the exception,

You also have to inject JobStorage and everything else that BackgroundJobClient uses. This is what I did:

public static void Register(IUnityContainer container, string connectionString)
    container.RegisterType<JobStorage, SqlServerStorage>(new InjectionConstructor(connectionString));
    container.RegisterType<IJobFilterProvider, JobFilterAttributeFilterProvider>(new InjectionConstructor(true));
    container.RegisterType<IBackgroundJobFactory, BackgroundJobFactory>();
    container.RegisterType<IRecurringJobManager, RecurringJobManager>();
1 Like