@PostConstruct

The @PostConstruct annotation is useful for initialization tasks that need to occur right after the object's construction but before dependency injection. This can be essential for setting up state or validating the object before dependencies are introduced.

import dev.fumaz.infuse.annotation.PostConstruct;

public class ConfigurationService {
    private Configuration config;

    public ConfigurationService() {
        // Constructor code
    }

    @PostConstruct
    public void initialize() {
        // Perform initialization here, before dependencies are injected
        this.config = loadDefaultConfiguration();
    }

    @Inject
    private DatabaseService databaseService;

    // Rest of the class
}

Last updated