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
TRequestThe type of request that implements IUsecaseRequest.
TResponseThe 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
requestTRequestThe request containing input parameters for the use case.
callbackICallback<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
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:
- Attempts to serve from cache if the request is a local request
- Runs the main operation asynchronously via ActionAsync()
- Checks for cancellation before executing the main operation
- Handles exceptions and invokes appropriate callback methods
TryServeFromCache()
Attempts to serve the response from cache for local requests.
protected virtual bool TryServeFromCache()
Returns
- bool
trueif 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.