Operations
The Operation is the eighth step of the request flow, in between pre- and post-operation Actions. The operation represents the primary function of the route, whether to create, update, delete, or have some other side-effect on the data source. It is passed in the ApiContext<TModel, TUser> and the dataset to operate on. When creating or updating, this dataset is often ignored in favor of the parsed models available in the ApiContext<TModel, TUser>. However, in other cases, like when deleting, this dataset determines which models to operate on. Regardless of the source of the models, an Operation always returns an IEnumerable<T> containing the models it affected. This dataset is then passed to the post-operation Actions and Result Writer.
The Operation request flow step is optional. If no Operation is provided, the dataset remains unaffected and the route will serialize and return the dataset. This is typically how GET
requests are set up.
Important
Base Seltzr includes no Operations. Instead, use packages like Seltzr.EntityFramework
, Seltzr.EntityFrameworkCore
, and Seltzr.LinqToDB
which include customized Operations for working with the ORM.
Builder Methods
Low-Level Methods
These methods are primarily used when you've implemented your own IOperation<TModel, TUser> and want to attach it to a route.
High-Level Methods
There are no high-level builder methods for adding common Operations. Instead you'll typically set an Operation when creating a new route. See Routing for examples.
Examples
Using a custom Operation on a route
This example uses a custom Operation that updates an existing model or creates a new one.
app.UseSeltzr<MyModel>("addorupdate", api => {
api
.UseOperation<CreateOrUpdate<MyModel>>()
.CanPost();
});