Module.java 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import com.google.inject.AbstractModule;
  2. import java.time.Clock;
  3. import services.ApplicationTimer;
  4. import services.AtomicCounter;
  5. import services.Counter;
  6. /**
  7. * This class is a Guice module that tells Guice how to bind several
  8. * different types. This Guice module is created when the Play
  9. * application starts.
  10. *
  11. * Play will automatically use any class called `Module` that is in
  12. * the root package. You can create modules in other locations by
  13. * adding `play.modules.enabled` settings to the `application.conf`
  14. * configuration file.
  15. */
  16. public class Module extends AbstractModule {
  17. @Override
  18. public void configure() {
  19. // Use the system clock as the default implementation of Clock
  20. bind(Clock.class).toInstance(Clock.systemDefaultZone());
  21. // Ask Guice to create an instance of ApplicationTimer when the
  22. // application starts.
  23. bind(ApplicationTimer.class).asEagerSingleton();
  24. // Set AtomicCounter as the implementation for Counter.
  25. bind(Counter.class).to(AtomicCounter.class);
  26. }
  27. }