Copied to clipboard

Flag this post as spam?

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


  • Matthew Wise 271 posts 1373 karma points MVP 5x c-trib
    Apr 24, 2020 @ 10:10
    Matthew Wise
    0

    Injecting custom collection into a component breaks in 8.6.1

    Hi,

    I am using a custom Collection to register event handlers on publish etc. This was all working in 8.6.0 updated to 8.6.1 today and it is now not booting.

    Code:

    Collection

    public class EventHandlerCollection : BuilderCollectionBase<IEventHandler<IMyInterface>>
    {
        public IndexingEventHandlerCollection(IEnumerable<IEventHandler<IMyInterface>> items) : base(items)
        {
        }
    }
    

    Builder

    public class IEventHandlerCollectionBuilder : SetCollectionBuilderBase<IEventHandlerCollectionBuilder, EventHandlerCollection, IEventHandler<IMyInterface>>
    {
        protected override IEventHandlerCollectionBuilder This => this;
    }
    

    Composers

    [ComposeBefore(typeof(ComposerB))]
    public class ComposerA : IUserComposer
    {
        public void Compose(Composition composition)
        {
           ...
           composition.WithCollectionBuilder<EventHandlerCollectionBuilder>().Add<IEventHandler<MyClass>>();
           ...
        }
    }
    
    public class ComposerB : ComponentComposer<EventComponent>
    {
    }
    

    Component

    public class Component : IComponent
    {
        private readonly EventHandlerCollection _eventHandlerCollection;
    
        public SearchComponent(EventHandlerCollection eventHandlerCollection)
        {
            _eventHandlerCollection = eventHandlerCollection;
        }
    
        public void Initialize()
        {
            foreach (var eventHandler in _eventHandlerCollection)
            {
                ContentService.Unpublished += eventHandler.Unpublished;
                ContentService.Trashed += eventHandler.Trashed;
                ContentService.Published += eventHandler.Published;
            }
        }
    }
    

    Does anyone have an idea on what I missing or has changed?

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Apr 24, 2020 @ 10:20
    Warren Buckley
    100

    Hi Matt
    At first glance it seems OK, but with most things a little more context is needed please to help you out.

    What is the error you get at boot?
    Does anything in the log files give you an idea whats going wrong?!(I know horrible JSON - use Compact Log Viewer to help)

  • Matthew Wise 271 posts 1373 karma points MVP 5x c-trib
    Apr 24, 2020 @ 10:37
    Matthew Wise
    1

    Thanks Warren,

    Checking through the logs looks like I had my Registers in the wrong order on other related points.

    Note to self: Check your logs well :D

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Apr 24, 2020 @ 10:41
    Warren Buckley
    0

    Glad you found the solution Matt
    The logs does help report the order of composers etc and when it fails to boot it normally gives quite a detailed reason.

  • Ronald Barendse 39 posts 218 karma points hq c-trib
    Apr 24, 2020 @ 12:33
    Ronald Barendse
    0

    Also keep in mind ComponentComposer<T> is a normal IComposer, not an IUserComposer, so composing order might be impacted by that (although the ComposeBefore might overrule that).

    The IComponent is missing the Terminate method (probably not copy/pasted), but that should be an empty stub (and not throw a NotImplementedException).

Please Sign in or register to post replies

Write your reply to:

Draft