Example can be found here
Generally you just annotate your static
fields with @Dependency
in JavaPlugin
class,
add @Autowired
annotation to the fields (they also must be static
) that you want
to injectand invoke Injector#inject(JavaPlugin)
method on your plugin object.
public final class AwesomePlugin extends JavaPlugin {
@Dependency private static Database database;
@Override public void onLoad() {
database = new HibernateDatabase();
}
@Override public void onEnable() {
Injector.inject(this);
}
}
public final class PlayerService {
@Autowired private static Database db;
public CompletableFuture<DbResult> addPlayer(final DbPlayer dbPlayer) {
return CompletableFuture.supplyAsync(() -> db.createOrUpdate(dbPlayer));
}
}
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.NyanGuyMF</groupId>
<artifactId>dependency-injector</artifactId>
<version>1.0.3</version>
</dependency>
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.NyanGuyMF:dependency-injector:1.0.3'
}