Write elegant and testeable solutions on C# using a Monadic Framework
Choose your hero
await from maybeOrder in from order in _orderRepository.GetById(orderId) select OrderBehavior.TryCheckout(order) from result in maybeOrder.AwaitSideEffect(_orderRepository.Update) select result.Match(Ok, InternalServerError("Error"));
return await _orderRepository.GetById(orderId) .Select(order => OrderBehavior.TryCheckout(order)) .SelectMany(m => m.AwaitSideEffect(_orderRepository.Update)) .Select(m => m.Match(Ok, InternalServerError("Error")));
Inject Behaviors not Dependencies
With a monadic architecture your applications are going to have a pure business logic that allows you to write easy tests and do not depend of any other layer. Also, your side effects are going to be centralized.
Instead of injecting the dependencies in all your project, you just have to inject the behavior with the monads giving live the pure business logic interacting with the exterior world.
- Check our wiki!