5

When one subscribes an event programatically how does Sitecore determine the order of that event x the ones patched through configuration? Is there a way to control that?

For example when one opens the even item:created or item:saved it´s well known that if you register them through config it uses the order of config patched to execute but what if you subscribe an event programatically what does that mean? Which gets executed first and how to control that?

For example:

Sitecore.Events.Event.Subscribe("item:created", myArgs);

How does this event execution order relate to other item:created patched through configuration?

Update: This code is triggered as part of a processor hooked into the initialize pipeline.

2
  • Do you have hook also configured for class that is calling this event subcription? How it is configured? Sep 4, 2018 at 13:06
  • @PeterProchazka updated question description
    – Diego
    Sep 4, 2018 at 13:24

2 Answers 2

4

The configuration would already be loaded to execute that pipeline. Your added events would normally get sent to the end of any existing events.

Keep in mind though, you should not rely on event ordering.

Do NOT rely on event ordering. All event dispatches should be logically independent, as if they were occurring in parallel. Events are logically independent actions.

https://stackoverflow.com/a/374549/81631

4

Agree with Mark, the only addition to that is that dynamic subscribed events are executed after events from configuration.

From Sitecore.Events.Event.RaiseEvent:

result = GetConfigSubscribers().RaiseEvent(eventName, parameters);
DynamicSubscribers.RaiseEvent(eventName, parameters, result);

Where DynamicSubscribers would contain your programatically bound events and the GetConfigSubscribers would contain the config bound events

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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