Long story short: I'm trying to inject a UmbracoContextFactory and one of my custom services into my Hangfire task. All works ok if I follow the advise from the thread above, which is: I inject just UmbracoContextFactory. However when I inject also my custom service I start to receive following error:
Has anybody faced with such a issue before and can help?
indeed, my custom service uses UmbracoContextFactory by injection but when it comes to use it, in every single place following pattern is applied:
using (var cref = _umbracoContext.EnsureUmbracoContext())
{
// do stuff...
}
Maybe I need to clarify, the mentioned error appears during Task instance initialization, which means the execution does not even reach the construstor.
Another observation: when I inject IDummyTask (with all 3 services injected via DummyTask constructor) into some controller for example it also seems to work.
It looks like the issue with how Hangfire resolves dependencies (?)
Umbraco + Hangfire - injecting multiple services
Hello,
I have a similar issue to this one: https://our.umbraco.com/forum/using-umbraco-and-getting-started/110698-access-content-cache-from-hangfire-in-v10-11-whats-going-on
Long story short: I'm trying to inject a
UmbracoContextFactory
and one of my custom services into my Hangfire task. All works ok if I follow the advise from the thread above, which is: I inject justUmbracoContextFactory
. However when I inject also my custom service I start to receive following error:Has anybody faced with such a issue before and can help?
Hi Mateusz.
Does your own custom service use UmbracoContext that it not called by UmbracoContextFactory by any chance?
You need to be sure that all UmbracoContext is called by the Factory like.
Hi Bo,
indeed, my custom service uses
UmbracoContextFactory
by injection but when it comes to use it, in every single place following pattern is applied:Maybe I need to clarify, the mentioned error appears during Task instance initialization, which means the execution does not even reach the construstor.
It looks like its the IUmbracoContextAccessor that is coursein the error, but i am not sure.
How does your Class looks like?
Ok so here is a task class implementation:
When I remove
IImportTourDataService
from the constructor - all works fine. So it seems to be an issue.So here is the constructor's header from the
IImportTourDataService
implementation:Forgot to mention: both my services:
DummyTask
andImportTourDataService
are registered in IoC as transient.Another observation: when I inject
IDummyTask
(with all 3 services injected viaDummyTask
constructor) into some controller for example it also seems to work.It looks like the issue with how Hangfire resolves dependencies (?)
Did you find a solution to this? I'm having the same problem.
is working on a reply...