Interface IService<TModel, TFilter>
- Namespace
- Magicalizer.Domain.Services.Abstractions
- Assembly
- Magicalizer.Domain.Services.Abstractions.dll
Service of models: gets them with filtering, sorting, paging and inclusions, creates and edits them.
public interface IService<TModel, TFilter> where TModel : class, IModel where TFilter : class, IFilter
Type Parameters
TModelModel type.
TFilterFilter type.
Methods
CountAsync(TFilter?, CancellationToken)
Counts the models that match the filter.
Task<int> CountAsync(TFilter? filter = null, CancellationToken cancellationToken = default)
Parameters
filterTFilterFilter to apply.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
CreateAsync(TModel, CancellationToken)
Creates the model. If the database generates the primary key, the primary key values of the model are ignored, and the created model has the generated ones.
Task<TModel> CreateAsync(TModel model, CancellationToken cancellationToken = default)
Parameters
modelTModelModel to create.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<TModel>
Created model.
Exceptions
- ModelAlreadyExistsException
A model with the same primary key already exists.
EditAsync(TModel, CancellationToken)
Edits the model.
Task EditAsync(TModel model, CancellationToken cancellationToken = default)
Parameters
modelTModelModel to edit.
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
Exceptions
- ModelNotFoundException
The model doesn't exist (or isn't available through the query prefilters).
GetAllAsync(TFilter?, IEnumerable<ISorting<TModel>>?, int?, int?, IEnumerable<IInclusion<TModel>>?, CancellationToken)
Gets the models that match the filter, sorted and paged, with related models included.
Task<IEnumerable<TModel>> GetAllAsync(TFilter? filter = null, IEnumerable<ISorting<TModel>>? sortings = null, int? offset = null, int? limit = null, IEnumerable<IInclusion<TModel>>? inclusions = null, CancellationToken cancellationToken = default)
Parameters
filterTFilterFilter to apply.
sortingsIEnumerable<ISorting<TModel>>Sortings to apply (property paths with directions).
offsetint?Number of models to skip.
limitint?Maximum number of models to return.
inclusionsIEnumerable<IInclusion<TModel>>Inclusions to apply (property paths of related models).
cancellationTokenCancellationTokenToken to cancel the operation.
Returns
- Task<IEnumerable<TModel>>
Models that match the filter.
GetKeyValues(TModel)
Gets the primary key values of the model (e.g. to build the URL of a created model).
object?[] GetKeyValues(TModel model)
Parameters
modelTModelModel to get the primary key values of.
Returns
- object[]
Primary key values in the order of primary key properties.