Conversation
Added a new method `ToProblemDetails<T>` in `ResultExtensions` to convert `ErrorResult<T>` to `ProblemDetails`, improving API response handling. Updated `Error` class to include `ErrorType` for better error categorization, and introduced `ValidationError` class. Extended `Result` class with new `Failure` methods to handle collections of errors. These changes enhance error handling robustness and clarity.
Added logging capabilities to `ConfigurationBuilderExtensions.cs` by introducing `Microsoft.Extensions.Logging`. Configured a `LoggerFactory` to read from the "Logging" section and added debug and console logging in debug mode. Replaced exception throwing with error logging for missing Azure App Configuration endpoint, improving application robustness.
Simplified the request handling system by removing the `Result<T>` wrapper from `HandleAsync` methods in `IRequestHandler` interfaces. Updated `HandleAsync` to return plain `TResponse` for both parameterless and parameterized handlers. Added `MapGetQuery` and `MapGetQueryWithResult` methods in `EndpointRouteBuilderExtensions` to streamline GET endpoint mapping with support for different request and response patterns. Introduced `RequestHandlerBase<TRequest, TResponse>` abstract class to provide a reusable base for implementing request handlers, improving code organization and maintainability.
Refactored service registrations and handler implementations:
- Registered `InMemoryDatabase` as a singleton.
- Updated `CreateProductHandler` to use a logging decorator.
- Registered and decorated `ProductCreatedQuery` with `Result<Product>`.
- Introduced `CreateProductHandlerLoggingDecorator` for detailed logging.
- Simplified generic logging handlers and renamed `LoggingRequestHandler<TIn, TResult>` to `LoggingRequestHandler2`.
Streamlined endpoints:
- Updated `POST /product` to always return `Results.Ok()`.
- Replaced `MapGetQuery` with `MapGetQueryWithResult` for `GET /product/{id}`.
Removed `Result` wrapper from handlers, improved logging consistency, and cleaned up unused or redundant code.
Updated `CreateProductHandler` and related classes to use the `Result<T>` pattern, improving error handling and encapsulating success/failure states. Enhanced logging in decorators to provide detailed insights into both success and failure scenarios. Modified `/product` endpoint to work with `Result<CreateProductResponse>` and updated response handling logic. Streamlined logging logic in `LoggingRequestHandler2` and removed commented-out code. These changes improve robustness, consistency, and debugging capabilities across the application.
Introduced new `MapGetRequestHandler` methods to simplify the mapping of GET endpoints in ASP.NET Core applications. These methods support request/response handling, mapping functions, and `Result` objects. - Added overloads for handling requests and responses with or without mapping functions. - Ensured consistent HTTP response handling (`200 OK`, `400 Bad Request`, or `Problem`). - Validated input parameters (e.g., `mapper` functions) for better error handling. - Added XML documentation for improved clarity and usability. - Removed legacy code to enhance maintainability and extensibility.
Replaced `MapGetQueryWithResult` with `MapGetRequestHandlerWithResult` for the `/product/{id}` endpoint to align with a new request-handling pattern. Updated endpoint metadata to include a new name (`GetProductCreated`), summary, and description for improved clarity and documentation.
Updated `Infinity.Toolkit.csproj` to target both .NET 10.0 and .NET 9.0, enabling multi-framework support. Bumped version prefix from `1.2.0` to `1.3.0`. Enhanced the `Error` class by: - Adding a default value (`ErrorType.Failure`) for the `type` parameter in the constructor. - Introducing predefined error instances: `None` and `NullValue`. - Adding a `Validation` method to create validation errors with specific codes and messages.
Updated Infinity.Toolkit.TestUtils.csproj to target both .NET 10.0 and .NET 9.0, enabling multi-framework compatibility. Refactored assertions in ResultExtensionsTests to use Shouldly for improved readability and maintainability. Added validations for the `errors` collection in `problemDetails.Extensions`.
Updated the `<VersionPrefix>` property in the `Infinity.Toolkit.Azure.csproj` file from `1.0.0` to `1.0.1`. This version increment reflects a minor update or patch release, signaling updates, bug fixes, or improvements in the project.
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces significant refactoring to the Infinity.Toolkit library, focusing on enhancing error handling capabilities and modernizing the handler interfaces. The changes include breaking API modifications to support more flexible handler patterns and improved error type categorization.
Key Changes:
- Refactored
IRequestHandlerinterfaces to return concrete types instead ofResult<T>, with new "WithResult" variants for backward compatibility - Introduced
ErrorTypeenum with HTTP status code values to categorize errors (Validation, NotFound, Conflict, etc.) - Added new endpoint mapping methods (
MapGetRequestHandler,MapGetRequestHandlerWithResult) with better type safety and mapping support
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
src/Infinity.Toolkit/Result/Error.cs |
Added ErrorType enum with HTTP status codes, introduced ValidationError class, and enhanced Error constructor with type parameter |
src/Infinity.Toolkit/Result/Result.cs |
Added new Failure<T> overload accepting IReadOnlyCollection<Error> |
src/Infinity.Toolkit/Handlers/IRequestHandler.cs |
Breaking change: modified interface methods to return TResponse instead of Result<TResponse>, added RequestHandlerBase abstract class |
src/Infinity.Toolkit.AspNetCore/ResultExtensions.cs |
Updated ToProblemDetails to include errors collection in extensions, added overload for ErrorResult<T> |
src/Infinity.Toolkit.AspNetCore/EndpointRouteBuilderExtensions.cs |
Added multiple new endpoint mapping methods for handlers with and without Result wrapping, including mapper support |
src/Infinity.Toolkit.Azure/Configuration/ConfigurationBuilderExtensions.cs |
Removed AddAzureAppConfiguration service registration, changed error handling from exception to logging |
src/Infinity.Toolkit/Infinity.Toolkit.csproj |
Bumped version to 1.3.0 and added .NET 10.0 target framework |
src/Infinity.Toolkit.TestUtils/Infinity.Toolkit.TestUtils.csproj |
Added .NET 10.0 target framework |
src/Infinity.Toolkit.AspNetCore/Infinity.Toolkit.AspNetCore.csproj |
Bumped version to 1.2.0 |
tests/Infinity.Toolkit.Tests/ResultExtensionsTests.cs |
Updated test assertions to use Shouldly assertions and verify error collection in ProblemDetails extensions |
samples/HandlersSample/Program.cs |
Updated sample to demonstrate new handler patterns with Result wrapping and decorator patterns |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/Infinity.Toolkit.AspNetCore/EndpointRouteBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/Infinity.Toolkit.AspNetCore/EndpointRouteBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
|
|
||
| IResult response = result switch | ||
| { | ||
| Success => TypedResults.Ok(mapper(result)), |
There was a problem hiding this comment.
Incorrect usage of mapper function. The mapper should be applied to result.Value (the unwrapped TResponse), not to result (which is a Result). This line should be Success => TypedResults.Ok(mapper(result.Value)),.
| Success => TypedResults.Ok(mapper(result)), | |
| Success => TypedResults.Ok(mapper(result.Value)), |
src/Infinity.Toolkit.AspNetCore/EndpointRouteBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/Infinity.Toolkit.Azure/Configuration/ConfigurationBuilderExtensions.cs
Show resolved
Hide resolved
src/Infinity.Toolkit.Azure/Configuration/ConfigurationBuilderExtensions.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…land/infinity-toolkit into remove-result-from-handlers
This pull request introduces significant improvements to both the
Infinity.Toolkit.AspNetCorelibrary and the sample application, focusing on enhanced support for result-based request handlers and more flexible endpoint mapping. The changes modernize the handler registration patterns, improve error handling, and add new extension methods for mapping endpoints that returnResult<T>types, making it easier to build robust, composable APIs.Key changes include:
Endpoint Mapping Enhancements (
Infinity.Toolkit.AspNetCore)EndpointRouteBuilderExtensionsfor mapping GET endpoints that work with request handlers returningResult<T>types, including overloads that support mapping and transformation of results. These methods improve error handling and response formatting for both success and failure cases. [1] [2]Sample Application Modernization
Program.csto useResult<T>for response types, updated decorator registrations, and improved logging decorators for better diagnostics and error reporting. [1] [2] [3] [4] [5]MapGetRequestHandlerWithResultextension, demonstrating the new result-based pattern.Result.Failure. [1] [2] [3]Miscellaneous
1.2.0to reflect the addition of new features and breaking changes.These updates collectively make the toolkit and sample app more robust, extensible, and aligned with modern .NET API design practices.