Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Richard Ockerby 39 posts 214 karma points MVP 4x c-trib
    May 30, 2020 @ 13:55
    Richard Ockerby
    0

    Override Core Components

    Hi there,

    I'm hitting an error when saving members through a Hangfire task (already raised here https://github.com/umbraco/Umbraco-CMS/issues/8090).

    As a quick fix for the project I'm on I was looking for help in how to override core components?

    Specifically I'm looking to have a new version of this to contain the fix - https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Core/Compose/AuditEventsComponent.cs

  • Richard Ockerby 39 posts 214 karma points MVP 4x c-trib
    Jun 01, 2020 @ 08:33
    Richard Ockerby
    100

    Turns out there's a handy Components.Replace function as part of the Composition class which allows you to swap out components. An example of how to use this would be:

    using Umbraco.Core.Composing;
    using Umbraco.Core;
    
    namespace MyNamespace
    {
        public class TestComposer : IUserComposer
        {
            public void Compose(Composition composition)
            {
                composition.Components().Replace<Umbraco.Core.Compose.AuditEventsComponent, TestComponent>();
            }
        }
    
        public class TestComponent : IComponent
        {
            public void Initialize()
            {
            }
    
            //...All the stuff I want to do instead of the AuditEventsComponent!
    
            public void Terminate()
            {
            }
        }
    }
    

    Thanks to Rowan for the help on Slack!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies