Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I've followed Sebastiaan's example for allowing dependency injection in Hangfire Tasks, as found here: https://our.umbraco.com/forum/umbraco-8/96445-hangfire-dependency-injection#comment-316037
But, when I inject the IExamineManager and perform a query, I get 0 results...
I know the query is correct as the exact same code returns results when used in an API Controller:
Does anyone know what would be causing this? And are there any workarounds?
Just a thought, but have you tried wrapping your examine stuff inside a scope? in case it's a lack of transient scope on a background thread that's causing the issue?
using (_scopeProvider.CreateScope(autoComplete: true))
// Do your examine reading stuff here
There is an answer from Shannon here that gives a bit of context:
or might give you a steer to an answer.
No dice, just tried that but also got 0 results :(
I bet it does have something to do with it being a background task and not having a proper scope/context though.
I'm tempted to create an API that the HangFire task just pings to get results, but that just feels a bit hacky...
Try remove _scope?.Dispose(); in DisposeScope().
I had issues when rebuilding indexes with hangfire and this line disposed the umbraco context causing the rebuild to crash.
Thanks for your suggestion, no change though unfortunately :(
I think I had a similar problem when trying to do something similar with Hangfire.
For some reason, I found that some of the Umbraco services didn't work if you "just" passed the existing context. I never figured out the reason for that but instead I ended up creating my own and re-registering all the services using the following block of code:
var serviceContainer = new LightInject.ServiceContainer();
foreach (var t in (Current.Factory.Concrete as LightInject.ServiceContainer).AvailableServices)
serviceContainer.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider();
See if doing the same makes a difference for you :-)
I just tried using that inside of my composer, but I get the exception "No factory has been set" on Current.Factory.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted