ClearFeatureActions 1.1.0
See the version list below for details.
dotnet add package ClearFeatureActions --version 1.1.0
NuGet\Install-Package ClearFeatureActions -Version 1.1.0
<PackageReference Include="ClearFeatureActions" Version="1.1.0" />
<PackageVersion Include="ClearFeatureActions" Version="1.1.0" />
<PackageReference Include="ClearFeatureActions" />
paket add ClearFeatureActions --version 1.1.0
#r "nuget: ClearFeatureActions, 1.1.0"
#:package ClearFeatureActions@1.1.0
#addin nuget:?package=ClearFeatureActions&version=1.1.0
#tool nuget:?package=ClearFeatureActions&version=1.1.0
ClearFeatureActions
Description
ClearFeatureActions is a robust framework designed to encapsulate a request and its process flow within a feature. Each action serves as a subset of a specific feature, consisting of three main components: a request, a handler, and a validator. The feature action coordinates these components to ensure seamless functionality.
- The handler is responsible for executing the requests.
- The validator ensures that all validation checks are completed before any execution is attempted.
This approach guarantees that the workflow is robust and efficient. The project relies on FluentValidation for validation logic and FluentResults for managing execution results.
Features
- Encapsulation of request and process flow
- Robust validation using FluentValidation
- Efficient result management using FluentResults
Installation
To install ClearFeatureActions, add the following package references to your project file:
Usage
- Define a request by implementing the
IRequest<TResponse>
interface. - Implement a handler for the request by implementing the
IRequestHandler<TRequest, TResponse>
interface. - Optionally, implement a validator for the request by inheriting from
AbstractValidator<TRequest>
. - Register the feature actions in your service collection using the
AddFeatureActions
extension method.
Example
Here's an example of how to use the feature action framework with a sample request, handler, and execution in a dependency-injected service.
Step 1: Define the Request
A request to check if a user exists by their ID, returning a bool
.
public class CheckUserExistsRequest : IRequest<bool>
{
public int UserId { get; }
public CheckUserExistsRequest(int userId)
{
UserId = userId;
}
}
Step 2: Implement the Request Handler
Handles the request using a user repository.
public class CheckUserExistsHandler : IRequestHandler<CheckUserExistsRequest, bool>
{
private readonly IUserRepository _userRepository;
public CheckUserExistsHandler(IUserRepository userRepository)
{
_userRepository = userRepository;
}
public async Task<Result<bool>> Handle(CheckUserExistsRequest request, CancellationToken cancellationToken)
{
var exists = await _userRepository.ExistsAsync(request.UserId);
return Result.Ok(exists);
}
}
Step 3: Optional Validator
Ensures the UserId
is valid.
public class CheckUserExistsValidator : AbstractValidator<CheckUserExistsRequest>
{
public CheckUserExistsValidator()
{
RuleFor(x => x.UserId).GreaterThan(0).WithMessage("User ID must be greater than zero.");
}
}
Step 4: Register Dependencies Using AddFeatureActions
Automatically register all feature actions, handlers, and validators in Program.cs
or Startup.cs
:
var assembly = Assembly.GetExecutingAssembly(); // Get the current assembly
services.AddFeatureActions(assembly); // Auto-registers everything in DI
Step 5: Use the Feature Action in a Controller
Inject IFeatureAction<CheckUserExistsRequest, bool>
into a controller and expose an API endpoint.
[ApiController]
[Route("api/users")]
public class UsersController : ControllerBase
{
private readonly IFeatureAction<CheckUserExistsRequest, bool> _checkUserExistsAction;
public UsersController(IFeatureAction<CheckUserExistsRequest, bool> checkUserExistsAction)
{
_checkUserExistsAction = checkUserExistsAction;
}
[HttpGet("{userId}/exists")]
public async Task<IActionResult> CheckUserExists(int userId, CancellationToken cancellationToken)
{
var result = await _checkUserExistsAction.Execute(new CheckUserExistsRequest(userId), cancellationToken);
if (!result.IsSuccess)
return BadRequest(result.Errors); // Return validation errors if any
return Ok(new { Exists = result.Value });
}
}
License
This project is licensed under the MIT License. See the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- FluentResults (>= 3.16.0)
- FluentValidation (>= 11.11.0)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.3)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.1.1-preview4 | 171 | 6/19/2025 |
1.1.1-preview3 | 288 | 6/10/2025 |
1.1.1-preview2 | 75 | 6/6/2025 |
1.1.1-preview1 | 75 | 6/6/2025 |
1.1.0 | 107 | 4/26/2025 |
1.0.1 | 165 | 4/22/2025 |
1.0.0 | 171 | 4/2/2025 |