This content is archived. See latest version here

Last updated: Oct 22 2015

Example

The example below shows how it is possible to replace a component for the entire system, and in this particular example how the built-in EPiServer CMS page tree can be replaced with a custom page list component. First declare a replacement component.

C#
// 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
        Settings.Add(new Setting("content", "Hello World!", false));
        Settings.Add(new Setting("heading", "Hello World!", false));
    }
}

Then replace the page tree component using the IOC container by implementing the ConfigureContainer method of EPiServer.ServiceLocation.IConfigurableModule in an initialization module.

C#
public void ConfigureContainer(ServiceConfigurationContext context)
{
    context.Container.Configure(container =>
    {
        container.For<IComponent>().Add<MyCustomPageList>()
            .Named(typeof(PageTreeComponent).FullName);
    });
}

This will replace 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/