0

I need to get the context item to create a "SearchContext" in my repository class using the following configurator :

public class DependencyInjectionConfigurator : IServicesConfigurator
{
    public void Configure(IServiceCollection serviceCollection)
    {
        serviceCollection.AddTransient<Item>(m => Sitecore.Context.Item ??
            Sitecore.Context.Database
           .GetItem(Sitecore.Context.Site.StartPath));
    }
}

The example class is used in a pipeline and is pretty basic:

public class Example
{
    public Example(Item contextItem)
    {
        //do stuff
    }
}

I get the error:

Unable to resolve service for type 'Example' while attempting to activate 'CustomHttpRequestProcessor'.
InvalidOperationException: Unable to resolve service for type 'Example' while attempting to activate 'CustomHttpRequestProcessor'.]

I should mention I set resolve=true in the configuration

  • Remember in a pipeline/processor you need to set the attribute Resolve="true". If you already did that, please update your question. – jrap Mar 18 '19 at 16:36
  • yep, already did that. – Adam Hess Mar 18 '19 at 16:39
  • just checking.. Added the relevant config to register this.? – Gobinath Saminathan Mar 18 '19 at 17:06
  • yep /Sitecore/Services/Register and /Sitecore/Services/Configurator tags are all there – Adam Hess Mar 18 '19 at 17:16
  • 1
    Can you see your registration in http://[instance]/sitecore/admin/showservicesconfig.aspx? – sitecorium Mar 18 '19 at 22:02

Your Answer

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

Browse other questions tagged or ask your own question.