5

In the Sitecore doc Configuring Federated Authentication there are instructions to generate the URL links to initiate Federated Auth -- the lines are:

using Sitecore.Pipelines.GetSignInUrlInfo;
/*
[...]
*/
var args = new GetSignInUrlInfoArgs(site: "website", returnUrl: "/");
GetSignInUrlInfoPipeline.Run(corePipelineManager, args); 

How do I get an instance of the corePipelineManager in order to pass to the GetSignInUrlInfoPipeline? I tried using the

var corePipelineManager = Sitecore.DependencyInjection.ServiceLocator.ServiceProvider.GetService<BaseCorePipelineManager>();

But am getting an error below:

CS1928: 'System.IServiceProvider' does not contain a definition for 'GetService' and the best extension method overload 'System.Web.Mvc.DependencyResolverExtensions.GetService(System.Web.Mvc.IDependencyResolver)' has some invalid arguments

  • 1
    Have you tried var corePipelineManager = Sitecore.DependencyInjection.ServiceLocator.ServiceProvider.GetService(typeof(BaseCorePipelineManager));? – Marek Musielak Feb 23 '18 at 18:52
  • Marek -- you're correct - I was trying to put it directly into the razor but when I pulled it into the codebehind using your line it started working. – Watson Feb 26 '18 at 16:04
3

Your code is correct. Just add Microsoft.Extensions.DependencyInjectionnamespace. It contains ServiceProviderServiceExtensions extension class that adds generic methods to the IServiceProvider interface.

At the same time, I would recommend you to use a constructor injection. It is supported in Sitecore and it lets you avoid a ServiceLocator anti-pattern.

|improve this answer|||||
  • Wait do you get extra points for answering my questions on your blog AND stack over flow :) – Watson Feb 26 '18 at 16:03
  • @Watson ;) That blog is not mine. I'm just trying to monitor issues for the features I've done :) – Vyacheslav Pritykin Feb 27 '18 at 9:44

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.