What is Play Dependency Injection (DI)
Play Framework supports DI, which is one of the popular Design Patterns used to decouple Application components behavior from Application components dependencies resolution.
In simple terms, DI means resolving dependencies automatically by server/container, but not by the developer.
Benefits of DI
The following are the benefits of DI:
- Clear separation between actual business logic and dependency resolution
- Encourages Single Responsibility Principle (SRP)
- Ease of maintenance and testing
Play Framework supports the following two kinds of DI:
- Play Compile-time DI: This involves resolving dependencies automatically at compile-time.
- Play Run-time DI: This involves resolving dependencies automatically at runtime. Play Framework supports the Run-time DI based on JSR-330 (https://jcp.org/en/jsr/detail?id=330).
By default, Play Framework supports the Compile-time DI out of the box using Guice.
Let's explore the Play Compile-time DI in the next section using a simple Play...