Virtual Happy Hour is canceled this month due to Good Friday.
Try our conversational search powered by Generative AI!
AI OnAI Off
Virtual Happy Hour is canceled this month due to Good Friday.
I think I found the answer, thanks to: https://stackoverflow.com/questions/42945859/remove-a-service-in-asp-net-core-dependency-injection/42946802#answer-42946802
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class RemoveSuggestedPageTypesInitialization : IConfigurableModule
{
public void ConfigureContainer(ServiceConfigurationContext context)
{
var serviceDescriptor = context.Services
.FirstOrDefault(descriptor => descriptor.ServiceType == typeof(IContentTypeAdvisor));
if (serviceDescriptor != null)
context.Services.Remove(serviceDescriptor);
}
public void Initialize(InitializationEngine context) { }
public void Uninitialize(InitializationEngine context) { }
}
This works. I'm not sure if it is the "correct" approach.
Hi!
Try this in ConfigureContainer method:
context.Services.RemoveAll<IContentTypeAdvisor>();
context.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IContentTypeAdvisor, EmptyContentTypeAdvisor>());
EmptyContentTypeAdvisor:
public class EmptyContentTypeAdvisor : IContentTypeAdvisor
{
public IEnumerable<int> GetSuggestions(IContent parent, bool contentFolder, IEnumerable<string> requestedTypes)
{
return Enumerable.Empty<int>();
}
}
I got an exception during startup when I removed all instances of IContentTypeAdvisor, so that's why I added that empty implementation. Maybe I got the exception because because I tested it on a Commerce site.
In the CMS 11 training exercises, there is a lab to remove the Suggested Page Types for editors.
Create a ConfigurableModule
In CMS 12, the StructureMap DI is no longer used, so I'm unclear on how to remove or eject a configurable module in CMS 12.