# How to define an event handler?

  1. Open respective .kdomain file

  2. Define the event handler for the stream as follows, by choosing only those events that need to be handled on the write side:

    event-handler[LotteryStream] LotteryStream{
    	LotteryCreated,ParticipantAdded,LotteryRan
    }
    
  3. compile

  4. Write the handle code in the generated EventHandlerCode class.

    For example:

    object LotteryStreamEventHandlerCode extends LotteryStream.Group {
    
      override def handle(event: LotteryCreated, context: EventContext): Unit = {
        val row = LotteryRow(
          lotteryName = event.lotteryName,
          open = true
        )
        LotteryWriter().save(row)
      }
    
     ...
    
    }