Using lombok

Although DiVine removes a huge chunk of boilerplate code that would be used for your initialization processes. Your getters, setters and constructors could still take up a lot of space. It is generally recommended to use Lombok to get rid of those code overheads from the source code.

@Service
@Getter
class MinigameManager {
    private final List<Minigame> minigames = new ArrayList<>();
    
    @Inject
    private NetworkManager networkManager;
    
    // ... bunch of other fields
}
@Service
@RequiredArgsConstructor
class UserController {
    @Inject
    private final UserRepository repository;
    
    @Inject(token = "API_TOKEN")
    private final String apiToken;
    
    @AfterInitialized
    public void init() {
        repository.login(apiToken, Scope.READ | Scope.WRITE);
    }
}

The code above will generate a constructor for UserController, which will take in repository and apiToken as parameters. This will be fully compatible with DiVine.

Your code might need multiple constructors, where DiVine should use a generated one. You can still put @ConstructWith on these generated constructors.

You may explicitly specify null assertations for your injected fields. DiVine will guarantee to always create an instance for your services.

Last updated