Skip to content

Remove resource hooks in favor of resource middleware #259

@smyrman

Description

@smyrman

Hooks have several problems and limitations compared to middleware:

  • We need two methods (before and after hooks)
  • We can't control the flow as detailed as we would want (Find hooks can modify the query, Get hooks can't)
  • We can't abort/change the flow without raising an error (E.g. call patch instead of delete/clear to implement soft delete).

With middleware we get more power:

  • We can do both pre and post operations within a single method.
  • We can control the flow, e.g. call patch instead of delete to implement soft delete.
  • We can always modify the query.

I want to suggest completely removing resource hooks in favor of middleware. This may involve making resource.Resource an interface that can be wrapped, or we might decide it's sufficient to wrap the storage layer and document that as the way to implement hooks. It could also involve changing the methods of a resource to be settable (except for wrapper methods such as MultiGet), setting the methods to the storage layer method on initalization, and wrapping them when Resource.Use is called.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalA suggestion for change that has not been accepted

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions