Executing AggregateLifecycle.apply in a CompletableFuture returned from a CommandHandler

I’m doing initial investigation into the Axon Framework, and after looking through doc and code I wondered how I would execute AggregateLifecycle.apply from a CompletableFuture returned by an aggregates CommandHandler.

Altered from doc’s GiftCard example (https://docs.axonframework.org/part-i-getting-started/quick-start)):

I should clarify: Results in exception:

java.lang.IllegalStateException: Cannot request current Scope if none is active

So I wonder how I would make a scope associated with the aggregate active.

You can only call “apply” from within your Aggregate class. If you want to publish events from outside, you should use the EventBus directly.