Table of Contents

Class UsecaseBase<TRequest, TResponse>

Namespace
Cyclotron.Utilities.CleanArchitecture
Assembly
Cyclotron.Utilities.dll

Base class for implementing use cases following the Clean Architecture pattern.

public abstract class UsecaseBase<TRequest, TResponse> where TRequest : IUsecaseRequest where TResponse : IUsecaseResponse

Type Parameters

TRequest

The type of request that implements IUsecaseRequest.

TResponse

The type of response that implements IUsecaseResponse.

Inheritance
UsecaseBase<TRequest, TResponse>
Inherited Members

Remarks

Initializes a new instance of the UsecaseBase<TRequest, TResponse> class.

Constructors

UsecaseBase(TRequest, ICallback<TResponse>)

Base class for implementing use cases following the Clean Architecture pattern.

protected UsecaseBase(TRequest request, ICallback<TResponse> callback)

Parameters

request TRequest

The request containing input parameters for the use case.

callback ICallback<TResponse>

The callback handler to receive operation results.

Remarks

Initializes a new instance of the UsecaseBase<TRequest, TResponse> class.

Fields

Callback

Gets the callback handler to receive operation results.

protected readonly ICallback<TResponse> Callback

Field Value

ICallback<TResponse>

Request

Gets the request containing input parameters for this use case.

protected readonly TRequest Request

Field Value

TRequest

Methods

ActionAsync()

Performs the main use case operation asynchronously.

protected abstract Task ActionAsync()

Returns

Task

A Task representing the asynchronous operation.

Remarks

Override this method to implement the core business logic of the use case. This method is called after cache check (if applicable) and cancellation check.

Execute()

Executes the use case operation.

public void Execute()

Remarks

This method orchestrates the use case execution:

  1. Attempts to serve from cache if the request is a local request
  2. Runs the main operation asynchronously via ActionAsync()
  3. Checks for cancellation before executing the main operation
  4. Handles exceptions and invokes appropriate callback methods
The method executes asynchronously without blocking the calling thread.

TryServeFromCache()

Attempts to serve the response from cache for local requests.

protected virtual bool TryServeFromCache()

Returns

bool

true if the response was successfully served from cache; otherwise, false.

Remarks

Override this method to implement caching logic for local requests. If this method returns true, the ActionAsync() method will not be called. Default implementation returns false.