7

So recently noticed a compiler warning on a custom pipeline I wrote to override what pages "Page Not Found", "Layout Not Found" get redirected to (in order to make them site specific pages in a mutlisite solution).

'ExecuteRequest.ExecuteRequest()' is obsolete: 'Use another constructor overload with dependency injection.`

Any thoughts on how to properly implement these types of redirects now?

4
  • Pretty sure this one covers it all. sitecore.stackexchange.com/questions/221/…
    – Mark Cassidy
    Commented Jul 18, 2017 at 14:36
  • ExecuteRequest Handles Layout Not Found, Site Access Denied, Redirect to Login Page, plus I give the ability to configure different custom pages at a site level, so each site can customize the page it redirects to.
    – mtelligent
    Commented Jul 18, 2017 at 15:12
  • How are you using it in code?
    – Richard Seal
    Commented Jul 18, 2017 at 15:19
  • Just extending it and overriding the methods: e.g. MultiSitePageConfigurationPipeline : Sitecore.Pipelines.HttpRequest.ExecuteRequest
    – mtelligent
    Commented Jul 18, 2017 at 15:25

1 Answer 1

4

After taking this to Slack - here was the problem. In the base class, the default constructor is using poor mans DI to resolve the references:

[Obsolete("Use another constructor overload with dependency injection.")]
public ExecuteRequest()
  : this(ServiceLocator.ServiceProvider.GetRequiredService<BaseSiteManager>(), ServiceLocator.ServiceProvider.GetRequiredService<BaseItemManager>())
{
}

In the derived class, you need to have a constructor setup that injects the required dependencies and passes those through to the base class, like this:

public class MyDerivedClass : ExecuteRequest
{
    public MyDerivedClass(BaseSiteManager baseSiteManager, BaseItemManager baseItemManager)
     : this(baseSiteManager, baseItemManager)
    {
    }
}

Now the derived class is calling the new constructor in the base class and injecting the dependencies correctly.

2
  • This was the problem. Adding the constructor removed the compiler warning. Thanks for the help.
    – mtelligent
    Commented Jul 18, 2017 at 15:43
  • 3
    The derived processor needs resolve="true" set where this patch config takes place.
    – jrap
    Commented Sep 25, 2017 at 15:46

Your Answer

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

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