Details
Just to be clear, I've listed Kotlin in standalone snippet as it uses singleton object (unique to kt), but these Java examples above are fully compatible with Kotlin and here's the example:
I didn't list it earlier as I think that the object singleton variant suits best for Kotlin users, but that's purely an extra api sugar, like our reified function extensions (to e.g. Context).
> The plugin instance part feels very useful for an extension point perspective. "Just implement our interface and plug it into plugins.register for your own plugins"
To limit all variants, I'd personally make plugin constructor private & remove factory field, so we'd force all plugins to use the same approach, but I don't mind if we'd keep it open just in case. If we'd limit all variants just to the factory pattern, all plugins should implement it like that:
https://github.com/javalin/javalin/blob/bc0499db4e093ad31b9f044afbdc33abfe3b6765/javalin/src/main/java/io/javalin/plugin/bundled/BasicAuthPlugin.kt#L29-L31
And (optionally) provide a singleton object for kt users:
https://github.com/javalin/javalin/blob/bc0499db4e093ad31b9f044afbdc33abfe3b6765/javalin/src/main/java/io/javalin/plugin/bundled/BasicAuthPlugin.kt#L34
_Originally posted by @dzikoysk in https://github.com/javalin/javalin/pull/1945#issuecomment-1627792414_
Details
Just to be clear, I've listed Kotlin in standalone snippet as it uses singleton object (unique to kt), but these Java examples above are fully compatible with Kotlin and here's the example: