Loading...

Last updated: Oct 27 2016

Area: Episerver CMS Applies to versions: 10 and higher
Other versions:

Replacing a component globally

This topic describes how to replace a component from the entire system, in the Episerver user interface.

Example

The following example shows how to replace a component for the entire system. This example also shows how to replace the built-in Episerver CMS page tree with a custom page list component.

  1. Declare a replacement component.
    // A simple component implementation represented with a dijit content pane on the client side
    public class MyCustomPageList : ComponentBase
    {
        public MyCustomPageList() : base("dijit/layout/ContentPane") 
        {
            // Add "Hello World!" as non-persisted content to the dijit content pane
            this.Settings.Add(new Setting("content", "Hello World!", false));
        }
    }
    
  2. Replace the page tree component using the IOC container by implementing the ConfigureContainer method of EPiServer.ServiceLocation.IConfigurableModule in an initialization module.
    public void ConfigureContainer(ServiceConfigurationContext context)
    {
        context.Container.Configure(container =>
        {
            container.For<IComponent>().Add<MyCustomPageList>()
                .Named(new PageTreeComponent().DefinitionName);
        });
    }
    

    This replaces any creation of the PageTreeComponent with a new instance of the MyCustomPageList type that is created by the IOC container.


Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/