[2.5] Controllers instances and singletons

311 views
Skip to first unread message

Loic

unread,
Apr 6, 2016, 10:55:58 AM4/6/16
to play-framework
Hi,

I'm using Play with runtime DI in some projects, I've created a new project with 'activator new' and seen that controllers were generated with @Singleton annotation for the injected router.

Does that mean if I don't put @Singleton Play will create a new instance of a controller each times it's used?
I've never put this annotations on controllers before (in my 2.4/2.5 projects) so I'm wondering :)

Thanks

Loïc

Will Sargent

unread,
Apr 6, 2016, 9:47:33 PM4/6/16
to play-fr...@googlegroups.com

Yes.  Guice basically says that creating a new instance every time is faster and more thread-safe than resolving a singleton.


It's not what you'd expect, but it works out surprisingly often.



--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/fa811747-2b93-48cd-8778-abc6174a9559%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Loic

unread,
Apr 7, 2016, 12:45:07 AM4/7/16
to play-framework
Ok I see that's why the documentation only mentions the need to use a singleton when we need to keep a state.

Thanks for the clarification :)
Reply all
Reply to author
Forward
0 new messages