Class DispatcherDataService
- Namespace
- Arbiter.CommandQuery.Dispatcher
- Assembly
- Arbiter.CommandQuery.dll
Provides a data service for dispatching common data requests to a data store.
public class DispatcherDataService : IDispatcherDataService
- Inheritance
-
DispatcherDataService
- Implements
- Inherited Members
Remarks
This service acts as an abstraction for sending queries and commands to a dispatcher, enabling operations such as retrieving, creating, updating, and deleting entities in a consistent manner.
Constructors
DispatcherDataService(IDispatcher)
Initializes a new instance of the DispatcherDataService class.
public DispatcherDataService(IDispatcher dispatcher)
Parameters
dispatcher
IDispatcherThe dispatcher used to send requests.
Exceptions
- ArgumentNullException
Thrown when
dispatcher
is null.
Properties
Dispatcher
Gets the dispatcher used to send requests.
public IDispatcher Dispatcher { get; }
Property Value
Methods
All<TModel>(string?, TimeSpan?, CancellationToken)
Gets all models of the specified type from the data store.
public ValueTask<IReadOnlyCollection<TModel>> All<TModel>(string? sortField = null, TimeSpan? cacheTime = null, CancellationToken cancellationToken = default) where TModel : class
Parameters
sortField
stringThe field or property name to sort by
cacheTime
TimeSpan?Optional time to cache the results
cancellationToken
CancellationTokenThe request cancellation token
Returns
- ValueTask<IReadOnlyCollection<TModel>>
Awaitable task returning a list
TModel
Type Parameters
TModel
The type of the model
Create<TCreateModel, TReadModel>(TCreateModel, CancellationToken)
Creates the specified createModel
in the data store.
public ValueTask<TReadModel?> Create<TCreateModel, TReadModel>(TCreateModel createModel, CancellationToken cancellationToken = default) where TCreateModel : class where TReadModel : class
Parameters
createModel
TCreateModelThe model being created
cancellationToken
CancellationTokenThe request cancellation token
Returns
- ValueTask<TReadModel>
Awaitable task returning
TReadModel
Type Parameters
TCreateModel
The type of the create model.
TReadModel
The type of the read model.
Delete<TKey, TReadModel>(TKey, CancellationToken)
Deletes the model with the specified id
from the data store.
public ValueTask<TReadModel?> Delete<TKey, TReadModel>(TKey id, CancellationToken cancellationToken = default) where TReadModel : class
Parameters
id
TKeyThe identifier to delete.
cancellationToken
CancellationTokenThe request cancellation token
Returns
- ValueTask<TReadModel>
Awaitable task returning
TReadModel
Type Parameters
TKey
The type of the key.
TReadModel
The type of the read model.
GetUser(CancellationToken)
Gets the current user from the request.
public virtual ValueTask<ClaimsPrincipal?> GetUser(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenThe request cancellation token
Returns
Get<TKey, TModel>(IEnumerable<TKey>, TimeSpan?, CancellationToken)
Gets a list of models for the specified identifier keys from the data store.
public ValueTask<IReadOnlyCollection<TModel>> Get<TKey, TModel>(IEnumerable<TKey> ids, TimeSpan? cacheTime = null, CancellationToken cancellationToken = default) where TModel : class
Parameters
ids
IEnumerable<TKey>The identifier keys to get
cacheTime
TimeSpan?Optional time to cache the results
cancellationToken
CancellationTokenThe request cancellation token
Returns
- ValueTask<IReadOnlyCollection<TModel>>
Awaitable task returning a list
TModel
for the specified identifier keys
Type Parameters
TKey
The type of the key
TModel
The type of the model
Get<TKey, TModel>(TKey, TimeSpan?, CancellationToken)
Gets the model for the specified identifier key from the data store.
public ValueTask<TModel?> Get<TKey, TModel>(TKey id, TimeSpan? cacheTime = null, CancellationToken cancellationToken = default) where TModel : class
Parameters
id
TKeyThe identifier key to get
cacheTime
TimeSpan?Optional time to cache the results
cancellationToken
CancellationTokenThe request cancellation token
Returns
- ValueTask<TModel>
Awaitable task returning the
TModel
for the specified identifier key
Type Parameters
TKey
The type of the key
TModel
The type of the model
Page<TModel>(EntityQuery?, CancellationToken)
Gets page of models based on the specified EntityQuery query.
public ValueTask<EntityPagedResult<TModel>> Page<TModel>(EntityQuery? entityQuery = null, CancellationToken cancellationToken = default) where TModel : class
Parameters
entityQuery
EntityQuerycancellationToken
CancellationTokenThe request cancellation token
Returns
- ValueTask<EntityPagedResult<TModel>>
Awaitable task returning a paged result for
TModel
Type Parameters
TModel
The type of the model
Save<TKey, TUpdateModel, TReadModel>(TKey, TUpdateModel, CancellationToken)
Saves the specified updateModel
in the data store with the specified id
.
If the model already exists, it will be updated; otherwise it will be created.
public ValueTask<TReadModel?> Save<TKey, TUpdateModel, TReadModel>(TKey id, TUpdateModel updateModel, CancellationToken cancellationToken = default) where TUpdateModel : class where TReadModel : class
Parameters
id
TKeyThe identifier to apply the update to.
updateModel
TUpdateModelThe update model to apply.
cancellationToken
CancellationTokenThe request cancellation token
Returns
- ValueTask<TReadModel>
Awaitable task returning
TReadModel
Type Parameters
TKey
The type of the key.
TUpdateModel
The type of the update model.
TReadModel
The type of the read model.
Search<TModel>(string, EntityFilter?, CancellationToken)
Searches the data store for models based on the specified search text and optional filter. TModel
must implement ISupportSearch
public ValueTask<IEnumerable<TModel>> Search<TModel>(string searchText, EntityFilter? entityFilter = null, CancellationToken cancellationToken = default) where TModel : class, ISupportSearch
Parameters
searchText
stringThe search text to search for
entityFilter
EntityFilterOptional additional filter for search
cancellationToken
CancellationTokenThe request cancellation token
Returns
- ValueTask<IEnumerable<TModel>>
Awaitable task returning a list
TModel
Type Parameters
TModel
The type of the model
Select<TModel>(EntitySelect?, TimeSpan?, CancellationToken)
Gets models based on the specified EntitySelect query from the data store.
public ValueTask<IReadOnlyCollection<TModel>> Select<TModel>(EntitySelect? entitySelect = null, TimeSpan? cacheTime = null, CancellationToken cancellationToken = default) where TModel : class
Parameters
entitySelect
EntitySelectcacheTime
TimeSpan?Optional time to cache the results
cancellationToken
CancellationTokenThe request cancellation token
Returns
- ValueTask<IReadOnlyCollection<TModel>>
Awaitable task returning a list
TModel
Type Parameters
TModel
The type of the model
Update<TKey, TUpdateModel, TReadModel>(TKey, TUpdateModel, CancellationToken)
Updates the specified updateModel
in the data store with the specified id
.
public ValueTask<TReadModel?> Update<TKey, TUpdateModel, TReadModel>(TKey id, TUpdateModel updateModel, CancellationToken cancellationToken = default) where TUpdateModel : class where TReadModel : class
Parameters
id
TKeyThe identifier to apply the update to.
updateModel
TUpdateModelThe model being updated
cancellationToken
CancellationTokenThe request cancellation token
Returns
- ValueTask<TReadModel>
Awaitable task returning
TReadModel
Type Parameters
TKey
The type of the key.
TUpdateModel
The type of the update model.
TReadModel
The type of the read model.