Skip to content

Serenity Service Handlers (Serenity Framework Repository in old versions) overridable methods and calling sequence

Jin edited this page Sep 13, 2023 · 1 revision

SAVE HANDLER

MySaveHandler : SaveRequestHandler

Properties:

     protected static IEnumerable<ISaveBehavior> cachedBehaviors;
     protected IEnumerable<ISaveBehavior> behaviors;

     public SaveRequestHandler();

     public IDbConnection Connection { get; }
     public bool IsCreate { get; }
     public bool IsUpdate { get; }
     public TRow Old { get; protected set; }
     public TSaveRequest Request { get; protected set; }
     public TSaveResponse Response { get; protected set; }
     public TRow Row { get; protected set; }
     public IDictionary<string, object> StateBag { get; }
     public IUnitOfWork UnitOfWork { get; protected set; }

     public TSaveResponse Process(IUnitOfWork unitOfWork, TSaveRequest request, SaveRequestType requestType = SaveRequestType.Auto);

Calling sequence of the overiddable methods:

  1. protected override IEnumerable GetBehaviors()
  2. protected override void ValidateAndClearIdField()
  3. protected override void LoadOldEntity() // Loads in base.Old the data before modification (also in PrepareQuery))
  4. protected override SqlQuery PrepareQuery()
  5. protected override void ValidateRequest()
  6. protected override void ValidatePermissions()
  7. protected override HashSet ValidateEditable()
  8. protected override void GetEditableFields(HashSet editable) // Gets the only editable fields of the entity
  9. protected override void ValidateEditableFields(HashSet editable)
  10. protected override void ValidateRequired(HashSet editableFields)
  11. protected override void ValidateIsActive()
  12. protected override void ValidateFieldValues()
  13. protected override void GetRequiredFields(HashSet required, HashSet editable) // Gets the mandatory fields and the editable fields of the entity
  14. protected override void SetInternalFields()
  15. protected override void BeforeSave() // Serenity.Services.ISaveRequest.Entity holds the current data
  16. protected override void ClearNonTableAssignments()
  17. protected override void ExecuteSave()
  18. protected override void InvalidateCacheOnCommit()
  19. protected override void AfterSave()
  20. protected override void HandleDisplayOrder(bool afterSave)
  21. protected override void PerformAuditing()
  22. protected override void OnReturn() // Last called

DELETE HANDLER

MyDeleteHandler : DeleteRequestHandler

Properties:

     protected static IEnumerable<IDeleteBehavior> cachedBehaviors;
     protected IEnumerable<IDeleteBehavior> behaviors;
     protected TDeleteRequest Request;
     protected TDeleteResponse Response;
     protected TRow Row;

     public DeleteRequestHandler();

     public IDbConnection Connection { get; }
     public IDictionary<string, object> StateBag { get; }
     public IUnitOfWork UnitOfWork { get; protected set; }

     public TDeleteResponse Process(IUnitOfWork unitOfWork, TDeleteRequest request);

Calling sequence of the overiddable methods:

  1. protected override IEnumerable GetBehaviors()
  2. protected override void ValidatePermissions()
  3. protected override void LoadEntity()
  4. protected override void PrepareQuery(SqlQuery query)
  5. protected override void ValidateRequest()
  6. protected override void OnBeforeDelete()
  7. protected override void ExecuteDelete()
  8. protected override void InvalidateCacheOnCommit()
  9. protected override void OnAfterDelete()
  10. protected override void DoAudit()
  11. protected override void OnReturn() // Last called

RETRIEVE HANDLER

MyRetrieveHandler : RetrieveRequestHandler

Properties:

    protected static IEnumerable<IRetrieveBehavior> cachedBehaviors;
    protected IEnumerable<IRetrieveBehavior> behaviors;
    protected TRetrieveRequest Request;
    protected TRetrieveResponse Response;
    protected TRow Row;

    public RetrieveRequestHandler();

    public IDbConnection Connection { get; }
    public SqlQuery Query { get; }
    public IDictionary<string, object> StateBag { get; }

    public TRetrieveResponse Process(IDbConnection connection, TRetrieveRequest request);

Calling sequence of the overiddable methods:

  1. protected override IEnumerable GetBehaviors()
  2. protected override void ValidateRequest()
  3. protected override void ValidatePermissions()
  4. protected override SqlQuery CreateQuery()
  5. protected override void PrepareQuery(SqlQuery query)
  6. protected override void SelectFields(SqlQuery query)
  7. protected override bool CanSelectField(Field field) // This method is called for each field
  8. protected override bool ShouldSelectField(Field field) // This method is called for each field
  9. protected override void SelectField(SqlQuery query, Field field) // This method is called for each field
  10. protected override void OnBeforeExecuteQuery()
  11. protected override void OnAfterExecuteQuery()
  12. protected override void OnReturn() // Last called

LIST HANDLER

MyListHandler : ListRequestHandler

Properties:

    protected static IEnumerable<IListBehavior> cachedBehaviors;
    protected IEnumerable<IListBehavior> behaviors;
    protected TListRequest Request;
    protected TListResponse Response;
    protected TRow Row;

    public ListRequestHandler();

    public IDbConnection Connection { get; }
    public SqlQuery Query { get; }
    public IDictionary<string, object> StateBag { get; }

    public TListResponse Process(IDbConnection connection, TListRequest request);

Calling sequence of the overiddable methods:

  1. protected override IEnumerable GetBehaviors()
  2. protected override void ValidateRequest()
  3. protected override void ValidatePermissions()
  4. protected override SqlQuery CreateQuery()
  5. protected override void PrepareQuery(SqlQuery query)
  6. protected override void SelectFields(SqlQuery query)
  7. protected override bool AllowSelectField(Field field) // This method is called for each field
  8. protected override bool ShouldSelectField(Field field) // This method is called for each field
  9. protected override void SelectField(SqlQuery query, Field field) // This method is called for each field
  10. protected override void ApplyKeyOrder(SqlQuery query)
  11. protected override void ApplyContainsText(SqlQuery query, string containsText)
  12. protected override void ApplySort(SqlQuery query)
  13. protected override void ApplySortBy(SqlQuery query, SortBy sortBy)
  14. protected override void ApplyFilters(SqlQuery query)
  15. protected override void ApplyEqualityFilter(SqlQuery query)
  16. protected override void ApplyCriteria(SqlQuery query)
  17. protected override void ApplyIncludeDeletedFilter(SqlQuery query)
  18. protected override void OnBeforeExecuteQuery()
  19. protected override MyRow ProcessEntity(MyRow row) // Once per record
  20. protected override void OnAfterExecuteQuery()
  21. protected override void OnReturn() // Last called

Clone this wiki locally