-
Notifications
You must be signed in to change notification settings - Fork 0
Factory annotation
Factory annotation is used to generate a stub factory interface at compile-time (with annotation processor) to be implemented at runtime with a factory code that create events instances.
Since EventSys recommends usage of interfaces to specify events rather than concrete classes, the creation of an instance of an event specified by an interface requires some code to be written. To avoid this, we introduced Factory interfaces feature:
interface MyFactory {
fun createBuyEvent(@Name("product") product: Product, @Name("amount") amount: Int): BuyEvent
}
This makes the process of creating new instances of events more easy and simple, you only need to use EventGenerator.createFactory to create instance of the factory, and then use it.
But if you have too much events, writting this stub interface can be tedious and even slow down the development, so @Factory was introduced.
Every event annotation that you wish to have a factory method in a factory interface should be annotated with @Factory. The value property is the name of target interface to add the factory method (the target interface cannot exists, Annotation Processor will create it).
Example:
@Factory("com.github.projectsandstone.eventsyswiki.MyFactory")
interface BuyEvent : Event {
val product: Product
val amount: Int
}
This will generate an factory stub interface, your implementation still need to be generated at runtime with EventGenerator.createFactory.
Container annotation to be used to specify multiple factories with @Factory, this is commonly used to generate variants with extensions.
These examples uses Kotlin language, to this work you need to configure Kotlin KAPT with EventSys as a kapt annotation processor.