Is there anyway to hook into IContentRepository.Save() method?

Vote:
 

Hi,

As you know in DataFactory we have some public events like: CreatedPage, SavedPage, MovedPage ... then we can hook some custom implementation into those events. But those events are only for PageData since EPiServer uses IContentRepository instead of DataFactory to manipulate BlockData then I'm wondering is there anyway to do the same for BlockData? 

Thank you very much!

#70955
May 06, 2013 13:10
Vote:
 

How about using some validator logic for this?

public class PageDataValidator : IValidate<PageData>
{
  public IEnumerable<ValidationError> Validate(PageData instance)
  {
    // TODO:   manipulate instace properties.
    return new ValidationError[0];
  }
}

    

I have used this approach to make sure the URLSegment property is always lower case. To validate other content types, simply change the type of class to validate in IValidate<T>

 

 

 

#70960
Edited, May 06, 2013 13:20
Vote:
 

Probably I didnt describe clearly, what I'd like to do is to hook into Published event while publishing a block.

#70961
May 06, 2013 13:24
Vote:
 

Ok, I sorted it out, there're also some equivalent events for block in DataFactory like: SavingContent, PublishingContent ... 

#70962
Edited, May 06, 2013 13:36
Vote:
 

If you do not want to access the events through direct access to DataFactory you can aslo find them defined on the interface IContentEvent which is registered in IOC container

#70965
May 06, 2013 14:03
Vote:
 

Very nice Johan!

#70981
May 06, 2013 18:53
Vote:
 

Thanks Johan for this tips. I was looking for this interface ages ago, but no luck. EPiServer SDK still need to be improved :)

#71018
May 07, 2013 12:18
Vote:
 

Small correction. The interface name is IContentEvents :)

#71537
May 22, 2013 10:44
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.