Skip to content

OkaeriPoland/okaeri-injector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Okaeri Injector

License Total lines Repo size Contributors Discord

Probably the most basic and simplest DI possible with just ~15kB in size. Part of the okaeri-platform.

Installation

Maven

Add repository to the repositories section:

<repository>
    <id>okaeri-repo</id>
    <url>https://storehouse.okaeri.eu/repository/maven-public/</url>
</repository>

Add dependency to the dependencies section:

<dependency>
  <groupId>eu.okaeri</groupId>
  <artifactId>okaeri-injector</artifactId>
  <version>2.1.0</version>
</dependency>

Gradle

Add repository to the repositories section:

maven { url "https://storehouse.okaeri.eu/repository/maven-public/" }

Add dependency to the maven section:

implementation 'eu.okaeri:okaeri-injector:2.1.0'

Example

More complex example can be found in the tests.

public class Worker {

    @Inject
    // @Inject("byName")
    private Api api;

    @PostConstruct
    private void initialize() {
        System.out.println("running api call");
        this.api.test();
    }
}
public final class TestInjector {

    public static void main(String[] args) {

        Injector injector = OkaeriInjector.create()
                // .registerInjectable("byName", new Api())
                .registerInjectable(new Api());

        Worker worker = injector.createInstance(Worker.class);
        System.out.println(worker);
    }
}
public class Api {

    public void test() {
        System.out.println("Hello World!");
    }
}

About

Probably the most basic and simplest DI possible

Topics

Resources

License

Stars

Watchers

Forks

Languages