DomainRepository in Java 8

Hi all,

I’d like to implement a DomainRepository in Java 8 but I can’t find any example of a DomainRepository interacting with EventStore to get and save aggregates written in Java 8.

Is there someone that can point me to an article or example project? BTW Google is full of articles “talking” about it but I can’t find an example of code.

Is that because is less common to use such a pattern in Java?

Thanks,

Daniel

Its just read from stream and append ...

http://docs.geteventstore.com/dotnet-api/3.0.1/reading-events/

and writing events

http://docs.geteventstore.com/dotnet-api/3.9.0/writing-to-a-stream/

The java 8 api is almost identical

btw: https://geteventstore.com/blog/20130220/getting-started-part-2-implementing-the-commondomain-repository-interface/

Hi Greg,

thanks for the links. The DomainRepository idea is straight forward: GetById, Save. It accepts any Aggregate specified as generic type by the client. The difficulties are more related to “how do that in pure Java”. I can imagine this can be implemented easily with Scala or Kotlin. But using just Java how you do something like that C#:

protected TResult BuildAggregate(IEnumerable events) where TResult : IAggregate, new()

{

var result = new TResult();

foreach (var @event in events)

{

result.ApplyEvent(@event);

}

return result;

}

You cannot instantiate generic types in that way and there is not a language constraints like : where… new().

We think that maybe in Java there are other ways to do that maybe simpler but we cannot find an example of a generic DomainRepository.