Copied to clipboard

Flag this post as spam?

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


  • wilmar 19 posts 129 karma points
    Feb 04, 2021 @ 08:31
    wilmar
    0

    I created an event on Umbraco 8 but the event is not fired ?

    where do i need tu put my events so they can be trigged ? this is my exampel code, i want this to be trigged on Published. i have my code in APP_DATA

    using System.Linq;
    using Umbraco.Core;
    using Umbraco.Web;
    using Umbraco.Core.Composing;
    using Umbraco.Core.Events;
    using Umbraco.Core.Models;
    using Umbraco.Core.Services;
    using Umbraco.Core.Services.Implement;
    using Umbraco.Core.Logging;
    
    namespace Extranet.Components
    {
        [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
        public class ProjectComposer : IUserComposer
        {
            public void Compose(Composition composition)
            {
    
            }
        }
    
        public class ProjectComponent : IComponent
        {
    
            //inject in the core Logger service
            private readonly ILogger _logger;
            public ProjectComponent(ILogger logger)
            {
                _logger = logger;
    
            }
    
            public void Initialize()
            {
                ContentService.Published += this.ContentService_Published;
            }
    
            public void Terminate()
            {
                //unsubscribe during shutdown
                // unsubscribe on shutdown
                ContentService.Published -= ContentService_Published;
            }
    
    
            private void ContentService_Published(Umbraco.Core.Services.IContentService sender, Umbraco.Core.Events.ContentPublishedEventArgs e)
            {
                // the custom code to fire everytime content is published goes here!
                _logger.Info<ProjectComponent>("Something has been published...");
                foreach (var publishedItem in e.PublishedEntities)
                {
                    _logger.Info<ProjectComponent>(publishedItem.Name + " was published");
                }
            }
    
    
    
        }
    }
    
  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Feb 04, 2021 @ 08:38
    Bjarne Fyrstenborg
    100

    Hi Wilmar

    You need to register your component in the composer:

    [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
    public class ProjectComposer : IUserComposer
    {
        public void Compose(Composition composition)
        {
            composition.Components().Append<ProjectComponent>();
        }
    }
    

    /Bjarne

  • wilmar 19 posts 129 karma points
    Feb 04, 2021 @ 13:10
    wilmar
    0

    Thanks :) !!

Please Sign in or register to post replies

Write your reply to:

Draft