Skip to main content

Introduction

Here let's talk about what is fairy IOC container and how it can be used to manage the dependencies of your application.

What is it?

Fairy container is a lightweight and easy-to-use dependency injection container for Java. It is designed to be simple and easy to use, yet powerful and flexible, Built on top of the Java Reflection API and uses annotations to define components and their dependencies. It is heavy inspired by Spring Framework.

Why use it?

Fairy container is designed to make your code more modular, testable, and maintainable. Let's see a very simple example to understand why you should use fairy container.


public class MyJavaPlugin extends JavaPlugin {

private final MyService myService;
private final MySecondService mySecondService;
private final MyThirdService myThirdService;

@Override
public void onEnable() {
myService = new MyService();
mySecondService = new MySecondService(myService);
myThirdService = new MyThirdService(myService, mySecondService);

myService.onPostInitialize();
mySecondService.onPostInitialize();
myThirdService.onPostInitialize();

this.getServer().getPluginManager().registerEvents(new MyListener(myService, mySecondService, myThirdService), this);
}

@Override
public void onDisable() {
myService.onPreDisable();
mySecondService.onPreDisable();
myThirdService.onPreDisable();
}

}

Essentially, fairy container allows you to define your components and their dependencies using annotations. This example is very small, but as your project grows, the benefits of using fairy container will become more and more apparent.

Fairy solves the problem of managing the dependencies of your application, and it does so in a way that is easy to use and understand. If you are familiar with Spring Framework, you will feel right at home with fairy container.

TL;DR

If you hate coding all those java boilerplate just like I do, fairy container is for you.

Look at the next section to get started with fairy container.