Skip to content

Latest commit

 

History

History
79 lines (65 loc) · 2.82 KB

README.md

File metadata and controls

79 lines (65 loc) · 2.82 KB

The Dependency Injector

A small and simple to use DI library for Spigot plugins

JitPack Tests CodeQL WTFPL

API usage

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));
    }
}

Maven

<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>

Gradle

repositories {
  maven { url 'https://jitpack.io' }
}

dependencies {
  implementation 'com.github.NyanGuyMF:dependency-injector:1.0.3'
}