ardalis / Result

A result abstraction that can be mapped to HTTP response codes if needed.
MIT License
866 stars 107 forks source link

New Feature: Add support for void returns #65

Closed csteele86 closed 5 months ago

csteele86 commented 3 years ago

Currently, Result enforces that it is of a specific type. This does not allow for times when no value is returned from a function (i.e., typically a delete or an update). Having this would allow us to still utilize the useful features of Result. From an API perspective, this would then become an HTTP 201 No Content.

ardalis commented 3 years ago

I looked into this, see https://github.com/ardalis/Result/issues/41.

It didn't work out; right now I forget what the main blockers were but I spent a bunch of hours on it and couldn't make it work the way I wanted to have both the generic and non-generic versions exist side by side. The way other similar frameworks handle this is by introducing a type that means "no return" like MediatR and its "Unit" type.

If folks think that would be a good general solution here, I could include such a type, and docs for how to use it, in this package. What do you think?

csteele86 commented 3 years ago

Yeah, I spent a little time trying to figure it out as well and ran into complications. I believe a good first place to start would be to have something. The way I've made it work in the solution we've adopted this package for sounds like the same way the other solutions have made it work.

ardalis commented 3 years ago

For reference see: https://github.com/jbogard/MediatR/blob/master/src/MediatR/Unit.cs or new link here: https://github.com/jbogard/MediatR/blob/master/src/MediatR.Contracts/Unit.cs

ardalis commented 5 months ago

I think this is done - reopen if there are still use cases not covered.