1

I am using sitecore workflow action in order to execute method, but the DI inject services not working, what i have to do to solve this issue ?

EX:

basiclly i have work flow that will call ResendAction to send some informations, and in this class i am using DI to inject some services , but the DI not working with this kind of sitecore background tasks, and i need to keep using DI to inject any service i need

public class ResendAction
{
    private readonly IRfiTasksHandler _rfiTasksHandler;

    public ResendAction(IRfiTasksHandler rfiTasksHandler)
    {
        _rfiTasksHandler = rfiTasksHandler
    }

    public void Process(WorkflowPipelineArgs args)
    {

    }

}

enter image description here

  • Can you give more information - show us what you have done already? (code, Sitecore version, ....) – Gatogordo May 27 '18 at 11:44
  • @Gatogordo Updated – M.Hasasneh May 27 '18 at 12:03
1

Sitecore DI will only resolve your instances in controllers and in pipelines where resolve=true is set.

<processor type="Foo.BarProcessor, Foo" resolve="true" /> 

You are going to have to new that up yourself.

private readonly IRfiTasksHandler _rfiTasksHandler;

public ResendAction()
{
    _rfiTasksHandler = DependencyResolver.Current.GetService<IRfiTasksHandler>();
}

public void Process(WorkflowPipelineArgs args)
{

}

If you're not using MVC or if you're in a Scheduled Task or otherwise outside page context, you can use the Service Locator code below to resolve it.

_rfiTasksHandler = ServiceLocator.ServiceProvider.GetService<IRfiTasksHandler>();
  • yes you are right , DependencyResolver.Current.GetService<IRfiTasksHandler>(); solved the issue – M.Hasasneh May 31 '18 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.