Skip to content
/ yadi Public

Yet another framework-agnostic skyhook dependency injection implementation for Java applications

License

Notifications You must be signed in to change notification settings

yalibs/yadi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yadi

Yet another framework-agnostic skyhook dependency injection implementation for Java applications.

This library is a fairly simple global store where you can store object instances and Supplier<T>'s. Even though it is simple, it can be very powerful.

Usage

Say you have an interfaced class called MyFoo like so:

interface IFooable {
    void foo();
}

class MyFoo implements IFooable {
    @Override
    public void foo() {
        // Do a thing
    }
}

Then you would inject the instance at program start like so:

public class Main {
    public static void main(String[] args) {
        DI.add(IFooable.class, new MyFoo());
        DI.lock(); // Do not allow any other place in the application to add more stuff to DI (optional)
        // start your application
    }
}

// ... further inside the application code ...

public class SomeService {
    private final IFooable injectedFooInstance;

    public SomeService() {
        this.injectedFooInstance = DI.get(IFooable.class);
    }
}

About

Yet another framework-agnostic skyhook dependency injection implementation for Java applications

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages