Alternate proposal for ASP.NET Core conversion #110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey Amichai,
sorry for taking so long, but I'm sick these days. I did a rather large refactoring regarding the conversion of
List<Error>
toIActionResult
andIResult
.What is done
ErrorOrOptions
now has less members. WithCustomToErrorActionResult
andCustomToErrorResult
, clients can completely circumvent our default implementation of the conversion.ProblemDetailsPrototype
which holds all properties of the problem details and the errors. This instance is then used to either createIActionResult
via our default implementation or theProblemDetailsFactory
, orIResult
via our default implementation. Clients can completely replace our creation of the prototype by usingErrorOrOptions.CustomCreatePrototype
.ErrorOrOptions.UseFirstErrorAsLeadingType
to true so that the leading type is determined by the first error in the collection. This algorithm does not apply if there only is one error.ErrorDefaults
. Clients can customize this dictionary with theoptions.ErrorDefaults
dictionary.MinimalApiTests
for an example. For this to work, I implementedErrorProblemDetails
and aErrorConverter
(this was necessary for the metadata dictionary).IActionResult
andIResult
object - seeCreateDefaultErrorResult
andCreateDefaultErrorActionResult
for details.What still needs to be done
Unauthorized
andForbidden
? These results usually have no problem details - should we handle them completely differently?TValue
isobject
- it would be great if we could changeError.Metadata
toDictionary<string, string>
. If we don't do that, we will have trouble with serialization as we either need to implement pretty complex conversion logic or throw runtime exceptions (as we do right now). Of course, this would be a breaking change.ErrorOrOptions
API, especially the delegates that exchange our default implementation should receive an options instance so they can act based on the info stored in there.Conclusion
IMHO, the ability to move error instances across processes and transform them back to
ErrorOr<TValue>
has a huge potential. Consider that a proxy service receives an HTTP request and uses another technology like MassTransit or GRPC to communicate with other backend services. When we adopt all those technologies, we could be the library that allows for easy integration between these, saving clients a huge amount of work, while decoupling their domain logic from I/O. This would set this library apart from similar libraries like FluentResults.