Tubing Core

The core plugin provides the IocContainer for Tubing framework. This dependency is always needed when developing a Tubing plugin

Beans

A Tubing bean is an instance of a class registered inside the Tubing IOC container. A bean can be registered in 2 ways.

  • Annotating the class with a bean annotation. The core plugin only provides @IocBean. But other dependencies can declare there own annotations to instantiate beans. This can be seen, for example, in the tubing-bukkit extension.

  • Providing the bean through a @TubingConfiguration class and provider method

A Tubing bean can only have one constructor! The parameters of the constructor can only be other Tubing beans or configuration properties injected with an @ConfigProperty annotation

Tubing can inject beans in 3 ways:

  • Inject a concrete class instance

  • Inject an interface with exactly one implementation

  • Inject a List of interface implementations.

Injection

Constructor injection

To inject properties we need to provide all needed beans inside the constructor of the class. Tubing will search for the dependencies and inject them.

Interface injection

If you have an interface with one implementation registered at runtime, Tubing will inject this one implementation. If you have multiple implementation of one interface at runtime Tubing will throw an exception indicating it can not inject the dependency as it does not know which to Inject. The permission handler is a good example of this. If you want multiple implementations of an interface you need a @IocMultiProvider and use List Injection.

List injection

You can inject a list of classes which all implement the same interface. To do so you need to annotate the bean with @IocMultiProvider and when injection you need to use the @IocMulti annotation.

An example of this could be (this is not a good example):

Example

ReportService bean

The ReportService is an example of a concrete class that is registered as a Tubing bean

ReportRepository bean

The ReportRepository is an interface that will have at runtime one bean registered inside the IOC container.

Mysql implementation

Notice the conditionalOnProperty . This means this specific implementation will only be instantiated and registered if the storage.type inside the config.yml is set to mysql.

Sqlite implementation

Notice the conditionalOnProperty . This means this specific implementation will only be instantiated and registered if the storage.type inside the config.yml is set to sqlite.

PermissionHandler bean

The permission handler in this example is an interface that will have at runtime one bean registered.

DefaultPermissionHandler

GroupManagerPermissionHandler

VaultPermissionHandler

Provider method

The below method decides which bean to register at runtime. This is another way to conditionally choose which interface implementation to register at runtime.

Last updated

Was this helpful?