Abstractions

Defines the CQRS handler and validator contracts for the Dosaic plugin framework. This package contains the core interfaces and models that resource handlers must implement — it has no runtime dependencies beyond FluentValidation and the Dosaic persistence/extensions abstractions, making it the right lightweight reference for libraries that need to declare handlers without pulling in full implementations.

Installation

dotnet add package Dosaic.Plugins.Handlers.Abstractions.Cqrs

Features

Handler interfaces (Dosaic.Plugins.Handlers.Abstractions.Cqrs.Handlers)

Interface
Method
Description

IHandler

Marker interface; all handlers must implement this

ICreateHandler<TResource>

CreateAsync(TResource, CancellationToken)

Creates a new resource and returns it

IUpdateHandler<TResource>

UpdateAsync(TResource, CancellationToken)

Updates an existing resource and returns it

IDeleteHandler<TResource>

DeleteAsync(IGuidIdentifier, CancellationToken)

Deletes a resource by its identifier

IGetHandler<TResource>

GetAsync(IGuidIdentifier, CancellationToken)

Retrieves a single resource by identifier

IGetListHandler<TResource>

GetListAsync(PagingRequest, CancellationToken)

Returns a paged list of resources

Validator interfaces (Dosaic.Plugins.Handlers.Abstractions.Cqrs.Validators)

Interface
Method
Description

IBaseValidator

Marker interface for all validators

ICreateValidator<TResource>

ValidateOnCreate(AbstractValidator<TResource>)

Validation rules applied before create

IUpdateValidator<TResource>

ValidateOnUpdate(AbstractValidator<TResource>)

Validation rules applied before update

IDeleteValidator<TResource>

ValidateOnDelete(AbstractValidator<TResource>)

Validation rules applied before delete

IGetValidator<TResource>

ValidateOnGet(AbstractValidator<TResource>)

Validation rules applied before get

IGetListValidator<TResource>

ValidateOnGetList(AbstractValidator<TResource>)

Validation rules applied before list

GenericValidator<T>

Concrete AbstractValidator<T> that delegates rule setup to an Action<AbstractValidator<T>>

Models (Dosaic.Plugins.Handlers.Abstractions.Cqrs.Models)

Type
Description

GuidIdentifier

Record implementing IGuidIdentifier. Has static Empty, New, and Parse(string) factory members

Enum

Type
Values

HandlerAction

Get, GetList, Create, Update, Delete

Usage

1. Define your resource model

Your resource must implement IGuidIdentifier from Dosaic.Plugins.Persistence.Abstractions:

2. Implement a validator

A single class can implement multiple validator interfaces, grouping all validation logic for a resource in one place:

3. Implement custom handlers

Use the handler interfaces when the built-in SimpleResource implementations (from Dosaic.Plugins.Handlers.Cqrs) do not fit your needs:

4. Use GuidIdentifier for request objects

GuidIdentifier is a ready-made implementation of IGuidIdentifier that can be used wherever a handler expects just an identifier:

If your resource has a repository registered in the DI container, you can skip writing handlers altogether by adding the CqrsSimpleResourcePlugin from Dosaic.Plugins.Handlers.Cqrs. It automatically registers generic SimpleResource*Handler<T> implementations for all five CQRS operations:

Resolved handler types:

Handler interface
Default implementation

ICreateHandler<TResource>

SimpleResourceCreateHandler<TResource>

IUpdateHandler<TResource>

SimpleResourceUpdateHandler<TResource>

IDeleteHandler<TResource>

SimpleResourceDeleteHandler<TResource>

IGetHandler<TResource>

SimpleResourceGetHandler<TResource>

IGetListHandler<TResource>

SimpleResourceGetListHandler<TResource>

Custom implementations registered in your own assemblies take precedence because the plugin scans for types that implement IHandler across all non-framework assemblies and registers them on top of the defaults.

Dependencies

Package
Purpose

Dosaic.Extensions.Abstractions

PagedList<T> used in IGetListHandler

Dosaic.Plugins.Persistence.Abstractions

IGuidIdentifier, PagingRequest

FluentValidation

AbstractValidator<T> used in validator interfaces

Last updated