Cannot request current Scope if none is active

Hello. I’m new to spring and to the Axon framework and I’m trying to wire up a small test project.

I’m getting a java.lang.IllegalStateException: Cannot request current Scope if none is active

My aggregate looks like this:

`
@Aggregate
class Film {
@AggregateIdentifier
lateinit var id: String
lateinit var name: String

@EventHandler
fun on(event: FilmCreatedEvent) {
this.id = event.id
this.name = event.name
}

}
`

and my command handler like this:

`
@Component
class FilmCommandHandler (
private val filmRepository: FilmRepository
) {

@CommandHandler
fun on(command: CreateFilmCommand) {
Assert.hasLength(command.id, “id missing”)
Assert.hasLength(command.name, “missing name”)

val event = FilmCreatedEvent(command.id, command.name)
AggregateLifecycle.appy(event) // ERROR
}
}
`

Can anyone point me in the right direction?

Tried doing AggregateLifecycle.apply instead AggregateLifecycle.appy ?

Aren’t they the same?

Hi Jack,

you can’t call apply() outside of your aggregate. Try moving your comand handler into your aggregate and removing the external command handler class.
Then, make sure the command handler that creates a new instance of your aggregate is actually a constructor. Commands that update an existing instance should be regular methods.

Hope this helps.
Cheers,

Allard

Thanks! I realized I was misunderstanding aggregates, all good now.