RA.Utilities.Feature.Abstractions
Namespace: RA.Utilities.Feature.Abstractions
The classes within the RA.Utilities.Feature.Abstractions namespace are the foundational base handlers for implementing the CQRS (Command Query Responsibility Segregation) pattern.
✨ Purpose and Function
Their primary purpose is to provide abstract base classes that your concrete command and query handlers can inherit from.
This approach is central to the Vertical Slice Architecture that the RA.Utilities library promotes.
By inheriting from these base handlers, you gain several key benefits "for free" without writing any boilerplate code:
- Automatic Logging: The base handlers automatically log the start and end of every request they process, providing consistent and valuable diagnostic information.
- Robust Exception Handling: Any unhandled exception that occurs within your handler's business logic is automatically caught.
It is then wrapped in a
Result.Failureobject (from theRA.Utilities.Corepackage), ensuring your application doesn't crash and returns a predictable error response. - Consistent Structure: They enforce a consistent structure for all your handlers by providing a single
HandleAsyncmethod that you must override. This is where you place your core business logic.
The main abstractions mentioned are:
IRequestHandler<TRequest, TResponse>: The most common base handler. It's used for features that process a request and are expected to return a value (e.g., creating a user and returning their ID, or fetching a product and returning its data).IRequestHandler<TRequest>: A base handler for "fire-and-forget" operations that process a request but do not return a value (e.g., queuing a background job).
🧠 Summary
In summary, the RA.Utilities.Feature.Abstractions classes are the cornerstone of the CQRS pattern in this framework, providing a robust, consistent, and low-boilerplate foundation for all your business logic features.
📄️ IRequest
In the MediatR pattern, IRequest and its generic counterpart IRequest are used to define the "messages" that your application sends. These messages can be either Commands (requests to change state) or Queries (requests to read data).
📄️ IRequestHandler
The primary purpose of an IRequestHandler is to contain the business logic for a single, specific feature (a command or a query).
📄️ IPipelineBehavior
The IPipelineBehavior interface defines a component that can participate in the processing of a request, allowing for the implementation of cross-cutting concerns.
📄️ INotification
The primary purpose of the INotification interface is to mark a class as a notification or event.
📄️ INotificationHandler
The INotificationHandler interface defines the contract for a class that handles a specific INotification.
📄️ INotificationBehavior
The INotificationBehavior interface defines a pipeline behavior that can be applied to the processing of an INotification.
📄️ IMediator
The IMediator interface is the central abstraction for dispatching requests and publishing notifications within your CQRS (Command Query Responsibility Segregation) architecture.
📄️ IPipeline VS INotification
How do IPipelineBehavior and INotificationBehavior