Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Cats extension module #61

Open
octonato opened this issue Sep 14, 2016 · 4 comments
Open

Add a Cats extension module #61

octonato opened this issue Sep 14, 2016 · 4 comments

Comments

@octonato
Copy link
Contributor

octonato commented Sep 14, 2016

The goal is to have an extension module that we can use Validated or Xor as return time for command handlers.

Things that need to be added

  • It should be possible to configure a Backend to use another Interpreter
  • The Cats extension must provide its own Backend for testing.
  • We should be able to reuse existing Interpreters, for instance: the AsyncInterpreter used by the Akka Backend. If we want Cats support, we need to augment the AsyncInterpreter and pass the augmented version to the Akka Backend
@patricknoir
Copy link

Hi Renato, given that Cats is deprecating Xor in favour of the new Either in scala 2.12 (right biased) do you see still see a value to provide support for Xor?

@octonato
Copy link
Contributor Author

octonato commented Sep 26, 2016

Good point. Scala 2.12 is almost there so we could put support for Xor on hold and have it only for the new biased Either.

And of course, support for Validated

@octonato
Copy link
Contributor Author

octonato commented Oct 1, 2016

I have done some progress on this (only analysis and some basic design) and some ideas and issues cames to the surface.

The main problem I'm facing right now is that whatever effect we choose on the behavior side, it always get transformed to the effect of the backend we use.

For instance, we have three effects that we can use when defining command handlers: Future, Try and Identity.

A command handler using Identity will return Identity when using the InMemoryBackend and it will be transformed to Future when using the AkkaBackend.

That means the the effects on the behavior definition are not necessarily preserved once executed by the backend.

I found a good solution to extend Actions with new effects: Validated, Either, scalaz.Validation, etc. This will give flexibility when defining command handlers, but whatever effect we choose, it will be discarded once executed. A Validated will have to be converted to a Future.

We will end-up with something like:

Validated[NonEmptyList[String],Events]
class InvalidException(errors: NonEmptyList[String])

// assuming AkkaBackend
val result = aggregateRef ? cmd
// in case of failures, result completes with 
// Failure(InvalidException)

Which is awkward.

The only way of having a Validated being returned by a command is by having a CatsBackend.

@octonato
Copy link
Contributor Author

octonato commented Nov 15, 2016

It's now possible to build an extensions (ie: new InvokerDirectives) for Cats (see #63).

However, I'm considering making Cats a full citizen in Fun.CQRS. I'm using it in an internal project right now, especially Validated and I'm quite happy with the results.

It's especially handy for fine-grained events. Whenever we have a Command that may emit many Events. In that case, if we reject the Command we can enumerate all the reasons why is was rejected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Fun.CQRS
In Progress
Development

No branches or pull requests

2 participants