4

We are using Castel windsor for DI in our Sitecore solution. Though we haven't done any IOC registration using Sitecore pipelines, It still resolves the Controllers. I'm fine with it. But the same is not working for Pipeline processors,

for ex:

Public class MyPipelineClass
{
    private IMyDependency myDependency;

    public MyPilelineClass(IMyDependency _myDependency){
        this.myDependency = _myDependency;
    }

    public void Process(PipelineArgs args)
    {
         myDependency.Execute();
     }
}

How can I achieve this sort of injecting dependencies to constructor of sitecore pipeline processor from Windsor container?

I'm ready to provide any specific details that'll help answering this question.

1 Answer 1

10

Assuming you're running Sitecore 8.2 or later, you can add resolve="true" to the <pipeline> element to enable DI resolution for the processor.

Sitecore uses Microsoft.Extensions.DependencyInjection for dependency injection, which doesn't appear to list Windsor as a supported container. It may be possible, but I'd seriously consider whether Windsor offers features/performance that make it worth it for your project to go "off the beaten path".

4
  • So, do you suggest using Microsoft.Extenstions.DependencyInjection for resolving pipelines, alongside using Castle Windsor for resolving Controllers??
    – nari447
    Apr 28, 2018 at 11:19
  • Controllers are automatically resolved using Microsoft.Extenstions.DependencyInjection by default. However, I believe the default container requires registration (ie. it won't look at a controller's ctor arguments unless you register it) Apr 28, 2018 at 11:51
  • Ok.. let me try this.
    – nari447
    Apr 28, 2018 at 12:22
  • 1
    I've ended up using castle for controllers(will plan to change this to use sitecore dependency injestionl later) and Microft.Extensions.DependencyInjection for Sitecore pipelines for now... Thank you, Richard.
    – nari447
    Apr 30, 2018 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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