dnikolovv / dev-adventures-realworld

A RealWorld application implemented using the Dev Adventures .NET Core template and functional programming.
https://marketplace.visualstudio.com/items?itemName=dnikolovv.dev-adventures-project-setup
142 stars 29 forks source link

Functional async #9

Open dzmitry-lahoda opened 4 years ago

dzmitry-lahoda commented 4 years ago

What do you think about replacing things like:

  public async Task<IActionResult> Get() =>
            Ok(new { tags = await _tagsService.GetAllAsync() });

to (whatever works)

 // use injection to see direct dependencies in each method
  public Task<IActionResult> Get([FromServices]ITagsService service) =>
                    service
                       .GetAllAsync()
                       .Ok(tags => new { tags = tags});
           //       service
           //            .GetAllAsync()
           //            .Next(tags =>Ok(new { tags = tags}));

So to speak it is possible to avoid await keyword(and still be async) in most cases and use pipelining. Looks like F#.

dnikolovv commented 4 years ago

As much as I like this approach, I think it's just going too far. I was kind of trying to find the balance between the standard (already familiar to most) and functional way of doing things. Sadly(?), C# is not a functional language, so I think it's better we stick to the "basics" where there's no obvious benefit of doing it functionally.