7

I am trying to read a component when an event system extension is first initialized in an 8.5 instance. So in my event system extension's constructor, I try to get the component from the Administrator session like this:

[TcmExtension("EventHandlerExtension")]
public class Event : TcmExtension
{
    public Event()
    {
        Session session = new Session("Administrator");
        Component component = (Component)session.GetObject("tcm:xx-xxxx-xx");
    }
}

When I do this, I get a timeout. This might be because the Network Service is not able to create an Administrator session during initialization.

enter image description here

However, when I try to use the Administrator session in an event handler (for example, when a component is saved), I am not seeing the timeout and the component is being retrieved.

public void HandleForComponentSaveInitiated(Component item, SaveEventArgs args, EventPhases phase)
{
    Session session = new Session("Administrator");
    Component component = (Component)session.GetObject("tcm:xx-xxxx-xx")
}

My questions are:

  • What is the best approach to read a Tridion item only once when an event system extension is first initialized?
  • Is Core Service the other option? (I know it is not recommended to use Core Service in an event system).

We are trying not to be dependent on DevOps for config updates so we would like to have our config settings stored in a Tridion component and have it read when the event system extension is initialized.

6

Instantiating Session object in the constructor of ES doesn't work from version 8 and beyond. We had this issue when we did the upgrade from 2013 to 8.5. So what we did is moved it to all event subscriptions methods. Please use it like that and forget about using Core Service in event system because it is an abomination, a Frankenstein which shouldn't exist hehhehhehe.

2

Instead of trying to do it in the constructor, I suggest using a Lazy<T> property to ensure that this configuration is only loaded once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.