# How to define an event handler?
Open respective .kdomain file
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 }compileWrite 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) } ... }