recently, I had to create a site with Umbraco and I ended up in a situation where I had multiple document type event handlers. However, as the events of "ContentService" are centralized, I had to use multiple "if" to check the document type of the current event and then execute the correct instructions based on the condition.
Therefore, I decided to create a small package that would allow me to create classes that handle specific document type events. Long story short, you can find such a class below:
[DocumentEventHandler(Include = new[] { "documentTypeA" })]
public class DocumentTypeAEventHandler : DocumentEventHandler
{
public override void Saving(IContentService contentService, SaveEventArgs<IContent> args)
{
base.Saving(contentService, args);
}
}
By using the DocumentEventHandler attribute, I'm able to narrow the overridden methods (Saving, Publishing, etc...) to be executed only for a specific document type. It is possible to use "Include" and "Exclude" properties to handle more than one document type.
More information can be found on the package page.
Don't hesitate to tell me what you think about it ;-)
Handling events differently
Hi,
recently, I had to create a site with Umbraco and I ended up in a situation where I had multiple document type event handlers. However, as the events of "ContentService" are centralized, I had to use multiple "if" to check the document type of the current event and then execute the correct instructions based on the condition.
Therefore, I decided to create a small package that would allow me to create classes that handle specific document type events. Long story short, you can find such a class below:
By using the
DocumentEventHandler
attribute, I'm able to narrow the overridden methods (Saving, Publishing, etc...) to be executed only for a specific document type. It is possible to use "Include" and "Exclude" properties to handle more than one document type.More information can be found on the package page.
Don't hesitate to tell me what you think about it ;-)
is working on a reply...