Play Framework dependency identification for vs @Singleton Class object

Play Framework 2.4 supports Google Guice Dependency Injection support

What is the advantage of using

@Singleton class A

instead

object A

for singletons?

+4
source share
1 answer

I see three advantages of using @Singleton classover objectif A has no dependencies:

  • If you want to test Aand declare it as @Singleton class, you have the opportunity to subclass it to extract some functions in your test, while this is not possible with object.

  • object, , A , , @Singleton class , A , , .

  • A, , @Singleton class.

A , @Singleton class , , (: a var getter/ ).

+5

Source: https://habr.com/ru/post/1616859/


All Articles