Skip to content

A small and simple library for Dependency Injection in your Spigot projects

License

Notifications You must be signed in to change notification settings

voidpointer0x00/dependency-injector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A small and simple library for Dependency Injection in your Spigot projects

Resources

License

Stars

Watchers

Forks

Languages