Order of execution of events subscribed programatically
Order of execution of events subscribed programatically
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.
@PeterProchazka updated question description
– Diego
Sep 4 '18 at 13:24
2 Answers
2
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
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
Thanks for contributing an answer to Sitecore Stack Exchange!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Do you have hook also configured for class that is calling this event subcription? How it is configured?
– Peter Procházka
Sep 4 '18 at 13:06