Table of Contents

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

TModel

Model type.

TFilter

Filter type.

Methods

CountAsync(TFilter?, CancellationToken)

Counts the models that match the filter.

Task<int> CountAsync(TFilter? filter = null, CancellationToken cancellationToken = default)

Parameters

filter TFilter

Filter to apply.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<int>

Number of models that match the filter.

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

model TModel

Model to create.

cancellationToken CancellationToken

Token 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

model TModel

Model to edit.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task

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

filter TFilter

Filter to apply.

sortings IEnumerable<ISorting<TModel>>

Sortings to apply (property paths with directions).

offset int?

Number of models to skip.

limit int?

Maximum number of models to return.

inclusions IEnumerable<IInclusion<TModel>>

Inclusions to apply (property paths of related models).

cancellationToken CancellationToken

Token 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

model TModel

Model to get the primary key values of.

Returns

object[]

Primary key values in the order of primary key properties.