@BeanSetup & @Bean

If you need to provide dependencies manually, you can use the @BeanSetup annotation.

A method (provider) that has @Bean annotations must return an object that will be added to the dependency list. Provider methods CAN BE STATIC!

import xyz.failutee.mineject.annotation.Bean;
import xyz.failutee.mineject.annotation.BeanSetup;

@BeanSetup
public class TaskServiceSetup {
    
    @Bean
    TaskService taskService() {
        return new TaskService();
    }
}

Provider method can also accept parameters that will be automatically injected into the method! You can also inject dependencies into the constructor.

import xyz.failutee.mineject.annotation.Bean;
import xyz.failutee.mineject.annotation.BeanSetup;
import xyz.failutee.mineject.annotation.Injectable;

@BeanSetup
public class TaskServiceSetup {

    @Injectable
    public TaskServiceSetup(TestManager testManager) {
        /* ... */
    }
    
    @Bean
    TaskService taskService(TestManager testManager) {
        return new TaskService();
    }
}

Last updated