2

As described in this article.

https://cardinalcore.co.uk/2014/07/02/sitecore-pipelines-commands-using-ioc-containers/

you can use pipeline "ref" and "factory" attributes, to use dependency injection on a pipeline.

There are newer ways of doing this since sitecore 8.2 (Infact 8.2 update 2 didn't work with this setup, and we had to wait for 8.2 update 3+) As we use Castle, we can't use the Dependency Resolver, as that doesn't call release and cause memory leaks. So utilising this older way of doing dependency injection, which does allow us to call release. (We also are using ControllerFactory for the same reason)

We've just started at looking at how much work to upgrade to Sitecore 9.

ISetting and IFactory have made Obsolete(Infact whole Sitecore.Abstraction.dll removed and moved to Sitecore.kernel.dll)

> Obsolete("Use Sitecore.Kernel!Sitecore.Abstractions.BaseCorePipelineManager instead.")] 
> public interface ICorePipeline
> 
> [Obsolete("Use Sitecore.Kernel!Sitecore.Abstractions.BaseFactory instead.")] 
> public interface IFactory
> 
> [Obsolete("Use Sitecore.Kernel!Sitecore.Abstractions.BaseRuleFactory instead.")] 
> public interface IRuleFactory

And instead of the interface has been replaced with abstract class.

Primary Question - Sitecore support have confirmed this works

Are these hooks still available in sitecore 9 to use "ref" and "factory" to do dependency injection in Sitecore 9? And do they work?

If so how can our Factory (which uses Castle) implement IFactory without getting a obsolete build warning, or how would we use the replacement base factory in a "ref" and "factory" scenario? Just realised that this is using the Sitecore.Reflection.IFactory

Resolved

Secondary Question

The "ISetting" & "ICorePipeline" & "IFactory" we were using in our Dependency Injection setup, how could we use the replacement abstract classes to achieve the old behaviour in our DI setup without getting the obsolete build warnings?

As we'll need to move away from this when this obsolete code is removed in a future version.

2

2 Answers 2

2

Primary Question

Sitecore support have come back, Ref & Factory are still available in sitecore 9.

The Sitecore.Reflection.IFactory has not been marked as obsolete, it's the Sitecore.Abstractions.IFactory that has been marked as obsolete.

Secondary Question

I've had a look at /sitecore/admin/ShowServicesConfig.aspx

and can see for BaseFactory the implementation is

Sitecore.Abstractions.BaseFactory, Sitecore.Kernel 
=>
Sitecore.Configuration.DefaultFactory, Sitecore.Kernel

for BaseRuleFactory the implementation is

Sitecore.Abstractions.BaseRuleFactory, Sitecore.Kernel 
=>
Sitecore.Rules.DefaultRuleFactory, Sitecore.Kernel    

for BaseCorePipelineManager the implementation is

Sitecore.Abstractions.BaseCorePipelineManager, Sitecore.Kernel 
=>
Sitecore.Pipelines.DefaultCorePipelineManager, Sitecore.Kernel    

for BaseSettings the implementation is

Sitecore.Abstractions.BaseSettings, Sitecore.Kernel
=>
Sitecore.Configuration.DefaultSettings, Sitecore.Kernel

We'll try updating our code to reference these new base classes, and register these default instances in our IoC container.

Not sure why the interfaces have been removed, and replaced with abstract classes.

Will mark this as closed once verified resolves our issues.

0

I am sure you have solved this by now but wanted to post what I ended up having to do to get the use of a container adaptor factory working for a processor in the getLayoutServiceContext pipeline for JSS. Rather than the ref and factory on the processor directly the processor ref pointed to an element in types node of the layoutService group.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <group groupName="layoutService">
          <types>
              <ExampleContextExtension 
              ref="SitecoreJss.Examples.ExampleContextExtension, SitecoreJss.Examples" 
              factory="FactoryContainerAdapter">
                <AllowedConfigurations hint="list">
                    <!-- Unless you change the Layout Service config used by your JSS app, this should always be present. -->
                    <jss>jss</jss>
                </AllowedConfigurations>
                <Applications hint="list">
                    <!-- Restrict the JSS apps for which this processor will execute. -->
                    <reactApp>JssReactWeb</reactApp>
                </Applications>
                <Routes hint="list">
                    <!-- Restrict the route items for which this processor will execute. IDs, item paths, and wildcard item paths are allowed. -->
                    <services>/sitecore/content/JssReactWeb/Home/Services*</services>
                    <portfolio>{BAD2C001-1746-4312-8422-B28806A1191E}</portfolio>
                </Routes>
              </ExampleContextExtension>
            </types>
        <pipelines>
          <getLayoutServiceContext>
            <processor ref="ExampleContextExtension"/>
          </getLayoutServiceContext>
        </pipelines>
      </group>
    </pipelines>
  </sitecore>
</configuration>

I have blogged on this also if you or anyone else is interested in more detail.

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.