Axon without Spring

Hi

Does anybody use Axon without Spring? And if yes, would you like to
share you project setup?

Cheers, Reto

I use Guice instead of Spring. Are you interested in that?

Hi

I’m also interested in the guice version .

Thanks

2011/11/1 Per Wiklander <per@wiklander.biz>

Yes, my prefered one would be JEE6 but guice sounds nice and maybe its
easier to transform.

I'm using EE 6, and let me tell you, CDI needs some work on
Glassfish!! Specifically you can run into some nasty classloader fun
with 3.1.x and pretty much any version of Weld (the default CDI
implementation). I think it's due to some issues with some changes
they made to the classloader code in glassfish in 3.1. I literally
get different results with constructor, field, and setter injection,
some work, some don't (caveat, I'm deploying via EAR with 2 wars, 1
ejb and dependencies in a shared jar and mixing in EJB 3.1 injections
as well).

That said, my setup is as follows:

JAX-RS Resource class -> CommandHandler<AggregateType> ->
Repository<AggregateType> -> EventStore

Since there is no defined DI spec in Axon (thankfully I might add!), I
just use @Inject annotations for setters on all the classes listed
above. My command handler is kind of tricky since I wanted multiple
commands handled in one class. I have each marked with @Singleton
(javax.inject.Singleton not javax.ejb.Singleton), and the command
handling methods marked with a @CommandHandler. On the constructor, I
have @Inject, with a CommandBus argument. I then do the following:

AnnotationCommandHandlerAdapter adapter = new
AnnotationCommandHandlerAdapter(this, commandBus);
adapter.subscribe();

Each command handler has the repository for the particular aggregate
it's used for injected as well via setter (you could easily do
constructor injection here too, infact, I'll mark that as TODO :slight_smile: My
repositories and event store are custom, so YMMV. I have my
repositories extend down to AbstractRepository<AggregateType> (or in
some cases I just implement the Repository<T> interface). The
repository implementations have @Singleton on the class again, and the
EventStore is injected via @Inject on a setter (again, you can do
constructor here, I tend to do setters on no-arg constructor POJO's
out of habit).

Now, my event store is a singleton since it's thread safe, but with
JPA and EntityManagers, you're not guaranteed thread safety (Spring
wraps the underlying EM impl with synchronized methods on a proxy, so
if you're using Spring you're good, I needed a non-locking impl so
again YMMV). Also, if you're not using event sourcing, the
persistence mechanism of choice for your app will determine what scope
to apply to the object.

Forgot to mention, I've got a partially completed demo app constructed
using EE 6. I'll give you a github URI once I've got it finished.

Hi Chad,

is that an Axon based app? If so, I'll link to it on the axon website.

Cheers,

Allard

Yes, it was constructed as a presentation aid for a local JUG
presentation I did on Axon/CQRS/ES. Unfortunately I didn't have time
to get it fully running before the presentation :slight_smile:

Hi Chad,

You mentioned publishing a git repo. I wonder if it was done already. I am very interested in your code.

Regards,

Minto