11. Creating Helper Methods using Operations

PROBLEM

There are occasions where you want to create operations that are shared by other operations for performing common tasks. The Helper Operations are typically not intended to be accessible from a web client, and there needs to be strategy for preventing web clients from accessing these Operations.

SOLUTION

Create an Operation that doesn't have a defined URL Mapping. This will result in an Operation that isn't directly accessible to web clients and is only accessible from other Operations using the Invoke Operation step. An Operation can have multiple mappings defined in the Web Controller. If an Operation has at least one mapping, the Operation is considered public. If a URL Mapping doesn't exist for Operation, the Operation is considered private.

It's also possible to define helper operations in the Service layer of the application, and service operations can called from the web layer using the Invoke Operation step.

HOW IT WORKS

Since a URL Mapping is responsible for defining the url(s) that will trigger an operation. Omitting or removing a URL Mapping for a specified operation will result in the operation only being available to other operations in the same controller.

RELATED RECIPES

  1. Mapping URLs to Operations and Views

  2. Reusing Operations in Different Contexts

  3. Hiding the Implementation Technology

  4. Implementing Post/Redirect/Get (PRG) Pattern