Playframework 2.4 Singletons, Object -
before playframework 2.4 used create object singleton class, , see singletons can achieved using @singleton annotation.
but, difference?
is using dependency injection @inject() ?
i afraid playframework 2.4 dependency injection enter in unnecessarily complicated way.
@singleton
part of jsr 330 standard , indeed dependency injection only. tells di framework create 1 instance of given class , use single instance across application. docs:
new instances created every time component needed. if component used more once, then, default, multiple instances of component created. if want single instance of component need mark singleton.
you can think of directive di framework create 1 instance. nothing holds creating multiple @singleton
annotated classes hand using new
.
singleton objects in scala in contrast true singletons , cannot instantiated hand.
Comments
Post a Comment