2

I am trying to register service with IoC Processor in SXA custom component But i have face error "the type or namespace name "IocProcessor"could not be found"

enter image description here

What should i go for resolved error.

0

While you can register the dependencies with config patch files like Alan Płócieniak mentioned, you can also achieve this through a configurator class which would be closer to what you have in your example:

public class RegisterVoteService : IServicesConfigurator    
    {
        public void Configure(IServiceCollection serviceCollection)
        {
            serviceCollection.AddTransient<IVoteRepository, VoteRepository>();
        }
} 

Then you register your configurator with a patch file:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <services>
            <configurator type="MyNamespace.RegisterVoteService, MyAssembly" />
        </services>
    </sitecore>
</configuration>

Now you can add more registrations to that configurator class as you need it.

3

I think that the documentation article (one that you probably used) is outdated because IocProcessor no longer exists (since 1.7 I believe).

For Controllers and Repositories you could use a trick from SXA. I described it here

For other services please use a new approach and register it in configuration, example below.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <services>
            <register serviceType="Sitecore.XA.Feature.Media.Services.IMediaItemService, Sitecore.XA.Feature.Media" implementationType="Sitecore.XA.Feature.Media.Services.MediaItemService, Sitecore.XA.Feature.Media" lifetime="Singleton"/>
        </services>
    </sitecore>
</configuration>

More about DI in Sitecore here

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.