lumio-medical / lumio-vault

A library providing dependency injection with JSR-330 annotations and extensible YML/JSON configuration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lumio Vault

GitHub Workflow Status Maven Central Repository javadoc GitHub FOSSA Status

This project is now archived, further developments should happen over at noleme-vault.

A library providing DI with JSR-330 annotations and extensible YML/JSON configuration.

Implementations found in this package shouldn't be tied to any specific Lumio project.

Note: This library is considered as "in beta" and as such significant API changes may occur without prior warning.

I. Installation

Add the following in your pom.xml:

<dependency>
    <groupId>com.lumiomedical</groupId>
    <artifactId>lumio-vault</artifactId>
    <version>0.11</version>
</dependency>

II. Notes on Structure and Design

TODO

III. Usage

A basic example of using this library with a yml configuration file:

Given a dummy configuration file my_conf.yml:

variables:
    my_var: 12.34
    my_other_var: "interesting"
    my_env_var: ${MY_VAR}

services:
    my_service:
        class: "me.company.MyClass"
        constructor:
            - "not so interesting"
            - "##my_var##"

    my_other_service:
        class: "me.company.MyOtherClass"
        constructor:
            - "##my_other_var##"

We could perform injection via annotations on a dummy class such as:

public class MyService
{
    private final MyClass service;
    private final MyOtherClass otherService;

    @Inject
    public MyService(MyClass service, @Named("my_other_service") MyOtherClass otherService)
    {
        this.service = service;
        this.otherService = otherService;
    }
}

..and do the following:

MyService service = Vault.with("my_conf.yml").instance(MyService.class);

It's also possible to use field annotations and proceed the following way:

public class MyService
{
    @Inject private MyClass service;
    @Inject private MyOtherClass otherService;
}
MyService service = Vault.with("my_conf.yml").inject(new MyService());

..one of the neat things we can do, is programmatically override parts of the configuration:

MyService service = Vault.with("my_conf.yml", defs -> {
    defs.setVariable("my_var", 34.56); //my_var will now equal 34.56 upon injection
}).inject(new MyService());

Alternatively we could directly query one of the declared services:

MyClass myService = Vault.with("my_conf.yml").instance(Key.of(MyClass.class, "my_service"));

Other features that will need to be documented include:

  • import of dependency json/yml files
  • service method invocation
  • service instantiation via static method call
  • service aliasing
  • service closing
  • service container composition
  • custom modules
  • custom preprocessing routines

TODO

IV. Dev Installation

This project will require you to have the following:

  • Java 11+
  • Git (versioning)
  • Maven (dependency resolving, publishing and packaging)

License

FOSSA Status

About

A library providing dependency injection with JSR-330 annotations and extensible YML/JSON configuration

License:MIT License


Languages

Language:Java 100.0%