Axon with Kotlin: method "apply" not acessible inside @CommandHandler mehtod

Hello people,

I am trying to use AxonFramework v3.2.2 inside my Koltin project. But Kotlin is recognizing the method **apply** as the kotlin inline function (from its stdlib), instead of the method **apply** located inside the AggregateLyfeCycle class (what I think would be the right one).

import org.axonframework.commandhandling.CommandHandler
import org.axonframework.commandhandling.model.AggregateIdentifier
import org.axonframework.eventsourcing.EventSourcingHandler
import org.axonframework.spring.stereotype.Aggregate
//other imports here ...

class Order {
    var id: Int = 0

    lateinit var user: User
    val products = mutableListOf<Product>()

    fun createOrder(command: CreateOrderCommand) {
        apply(OrderCreatedEvent(orderId = 1, user = command.user))  //Doesn't compile!

    fun on(event: OrderCreatedEvent) { = event.orderId

The error is:

Error:(22, 9) Kotlin: Type inference failed: inline fun T.apply(block: T.() -> Unit): T
cannot be applied to
receiver: Order arguments: (OrderCreatedEvent)

Do you know what could be the problem? Any help would be appreciated.

Got it.

The apply method is a static method, so it is needed to import it (or all it explicitly).

Java way:

import static org.axonframework.commandhandling.model.AggregateLifecycle.apply;

Kotlin way:

import org.axonframework.commandhandling.model.AggregateLifecycle.apply

Great you figured it out Fabricio and thanks for sharing that info with everybody!