-
Notifications
You must be signed in to change notification settings - Fork 10
Autowired
LeeGod edited this page Dec 28, 2021
·
2 revisions
Autowired is a powerful tool for you to lookup ContainerObject in a very easy way by doing field injection.
Annotation: io.fairyproject.container.Autowired
Any kind of ContainerObject will scan through all the fields and search if the field has @Autowired
annotation. it will search ContainerObject by field type, and inject into the field.
Example code:
package io.fairyproject.examplePlugin;
import io.fairyproject.container.Service;
import io.fairyproject.container.Autowired;
import io.fairyproject.module.ModuleService;
@Service
public class ExampleService {
@Autowired
private ModuleService moduleService;
...
All static field can be injected for Autowired, if the field has @Autowired
annotation. it will search ContainerObject by field type, and inject into the field.
Example code:
package io.fairyproject.examplePlugin;
import io.fairyproject.container.Autowired;
import io.fairyproject.module.ModuleService;
public class ExampleClass {
@Autowired
public static ModuleService MODULE_SERVICE;
...
@Autowired field can be any access level (public, protected, private). But you shouldn't set it to final or intialize the field.
Autowired injection will be done after Component
PRE_INIT
.