Passing Params to the ServicesConfigurator for DI in Sitecore
We are using the IServicesConfigurator interface to configure our services from code and registering it in the <services> section in the Sitecore config. However I had a situation where I wanted to pass some configuration values (to do with a custom cache) to the ServicesConfigurator in order to do something different. This was my ServicesConfigurator class before I made any changes: public class MvcControllerServicesConfigurator : IServicesConfigurator { public void Configure(IServiceCollection serviceCollection) { serviceCollection.AddMvcControllers(“*.Feature.*”); serviceCollection.AddClassesWithServiceAttribute(“*.Feature.*”); serviceCollection.AddClassesWithServiceAttribute(“*.Foundation.*”); //get my param values here } } This was the config for the pipeline: Normally in Sitecore pipelines we can just set Params in the config of the Pipeline (e.g <useMyCustomCache>true</useMyCustomCache>) and grab them within the pipeline class like so: public class MvcControllerServicesConfigurator : IServicesConfigurator { public string UseMyCustomCache { get; private set; } public void Configure(IServiceCollection serviceCollection) { … if(bool.Parse(UseMyCustomCache)){ //do something here } … However the this doesn’t work and causes an error like … Continue reading Passing Params to the ServicesConfigurator for DI in Sitecore