DotEmilu.Abstractions
2.0.0
dotnet add package DotEmilu.Abstractions --version 2.0.0
NuGet\Install-Package DotEmilu.Abstractions -Version 2.0.0
<PackageReference Include="DotEmilu.Abstractions" Version="2.0.0" />
<PackageVersion Include="DotEmilu.Abstractions" Version="2.0.0" />
<PackageReference Include="DotEmilu.Abstractions" />
paket add DotEmilu.Abstractions --version 2.0.0
#r "nuget: DotEmilu.Abstractions, 2.0.0"
#addin nuget:?package=DotEmilu.Abstractions&version=2.0.0
#tool nuget:?package=DotEmilu.Abstractions&version=2.0.0
DotEmilu
A simple, easy-to-use .NET library designed for handling HTTP requests and responses.
Features
- Supports GET, POST, PUT, and DELETE requests.
- Handles HTTP responses with status codes and error handling.
- Built with .NET 8 for cross-platform compatibility (Windows, Linux, macOS).
- Supports async/await for non-blocking HTTP calls.
- Includes request contracts and base constraints for verifiers.
- Provides an HttpHandler to simplify request handling.
- New extension method to register handlers using reflection for cleaner setup.
How to Use
Follow these simple steps to get started:
Build Your Logic
Create the logic for your application based on your previously defined request and expected response.public class FullUseCase( IVerifier<FullDto> verifier, IVerifier<InDto> verifierIn, IHandler<InDto> handlerIn) : Handler<FullDto, FullOutDto>(verifier) { private readonly IVerifier<FullDto> _verifier = verifier; protected override async Task<FullOutDto?> HandleUseCaseAsync(FullDto request, CancellationToken cancellationToken) { Console.WriteLine("Handling my primary use case..."); var requestIn = new InDto(request.Day); await WorksSecondCaseAsync(requestIn, cancellationToken); if (!verifierIn.IsValid) { _verifier.AddErrors(verifierIn.Errors.ToList()); _verifier.AddError("BehindCase", "Second case has errors"); return null; } return new FullOutDto(); } private async Task WorksSecondCaseAsync(InDto request, CancellationToken cancellationToken) => await handlerIn.HandleAsync(request, cancellationToken); }
Add Your Endpoint
Define your endpoint using either Minimal API or a Controller, depending on your project's structure.private static async Task<IResult> FullCase([FromBody] FullDto dto, HttpHandler<FullDto, FullOutDto> handler, CancellationToken cancellationToken) => await handler.HandleAsync(dto, cancellationToken, _ => Results.NoContent());
Register Your Dependencies
Ensure all required dependencies are registered in your application's dependency injection container.builder.Services .AddDotEmilu() .AddHandlers(Assembly.GetExecutingAssembly()) .AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
For a complete example
Notes:
You need to add the response messages for bad request (400) and server error (500)
{
"ResultMessage": {
"ValidationError": {
"Title": "Bad Request",
"Detail": "One or more errors"
},
"ServerError": {
"Title": "Server Error",
"Detail": "Please contact to administrator"
}
}
}
And for complex validation use fluent validation
public class SampleValidator : AbstractValidator<SampleRequest>
{
public SampleValidator()
{
RuleFor(s => s.Date)
.GreaterThanOrEqualTo(DateOnly.FromDateTime(DateTime.Now));
RuleFor(s => s.Amount)
.GreaterThan(0);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- FluentValidation (>= 11.11.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DotEmilu.Abstractions:
Package | Downloads |
---|---|
DotEmilu
Simple .NET library to handle use cases |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.0 | 158 | 25 days ago |
Initial release, contains basic contracts to handle general requests