Depenject - a lightweight, minimalistic dependency injection library for Kotlin/JVM.

Overview

depenject

depenject is a lightweight, minimalistic dependency injection library for Kotlin/JVM.

  • Our goal is similar to flavor's to simplify the usage of traditional dependency injectors, but instead an approach without annotations.
  • Just like flavor, we use kotlin-exclusive features such as reified types & inline functions and ReadWriteProperty
    • reified types & inline functions allows us to offer an easier approach to injecting & binding.
    • ReadWriteProperty is what we use to avoid having to use annotations. Soon will be used for more than what it's currently doing.
      • This also makes it (unfortunately) incompatible with Java and other JVM-specific languages.

Features

  • Basic object binding to key, with an optional named property to identify key/objects.
  • Basic injection using the aforementioned ReadWriteProperty .
  • Pipelining to easily retrieve several objects in just a single loop, allowing for further startup optimization.

Should this be used

If you prefer to not use annotations and are not planning to use this for production, feel free to test it out and/or use it for your own projects. Other than that, it's just a simple library I made for fun. Not expecting people to actually use it. flavor is a very good alternative, which has been tested way more than depenject, and has been tested on several occasions by the author, GrowlyX

Usage

After reading all of this and you still feel like you want to use this, here's some basic usages for injecting & binding.

() to 5 injector.bind() to 9 named "number2" // we're binding the Int type with value 9 to an identifier, namely the "number2" identifier. assertEquals("hey", InjectionTest.string) assertEquals(5, InjectionTest.number) assertEquals(9, InjectionTest.number2) } } object InjectionTest { // simple individual search, from global `injector` field val number by injector.inject() // pipelined search private val pipelined = Inject.by().pipelined() // here we're retrieving the registered Injector to the "String" parent. .addType() .addType("number2") // injection is named "number2" .search() // all methods following the .pipelined().search() method are the exact same implementation as in Injector and Inject, // but using a pipelined implementation for the backend instead, which means the methods are exactly the same as the aftermentioned classes. val string by pipelined.inject() val number2 by pipelined.inject() }">
val injector =
    Injector.create<String>() // this injector will now be bound to the String parent, and will thus be able to be retrieved using the String parent identifier.

class InjectTest
{
    @Test
    fun inject()
    {
        injector.bind<String>() to "hey" named "lol"
        injector.bind<Int>() to 5
        injector.bind<Int>() to 9 named "number2" // we're binding the Int type with value 9 to an identifier, namely the "number2" identifier.

        assertEquals("hey", InjectionTest.string)
        assertEquals(5, InjectionTest.number)
        assertEquals(9, InjectionTest.number2)
    }
}

object InjectionTest
{
    // simple individual search, from global `injector` field
    val number by injector.inject<Int>()

    // pipelined search
    private val pipelined =
        Inject.by<String>().pipelined() // here we're retrieving the registered Injector to the "String" parent.
            .addType<String>()
            .addType<Int>("number2") // injection is named "number2"
            .search()


    // all methods following the .pipelined().search() method are the exact same implementation as in Injector and Inject, 
    // but using a pipelined implementation for the backend instead, which means the methods are exactly the same as the aftermentioned classes.
    val string by pipelined.inject<String>()
    val number2 by pipelined.inject<Int>()
}
You might also like...
Collection of JVM library logic that the Sirloin software development team is currently using

Collection of JVM library logic that the Sirloin software development team is currently using

Create libraries for all types of Kotlin projects: android, JVM, Multiplatform, Gradle plugins, and so on.

JavierSC Kotlin template Create libraries for all types of Kotlin projects: android, JVM, Multiplatform, Gradle plugins, and so on. Features Easy to p

An implementation of MediatR on JVM for Spring using Kotlin coroutines

Kpring MediatR In this project, an attempt has been made to implement the mediator pattern on the JVM with simplicity using Kotlin with native corouti

Kotlin jvm + android packages for bdk-ffi

bdk-kotlin This project builds .jar and .aar packages for the jvm and android platforms that provide Kotlin language bindings for the bdk library. The

Kotlin SDK for Jellyfin supporting Android and the JVM.

Jellyfin Kotlin SDK Part of the Jellyfin Project The Jellyfin Kotlin SDK is a library implementing the Jellyfin API to easily access servers. It is cu

Asynchronous Spring Initializr API wrapper for Kotlin/JVM

initializr-kt Asynchronous Spring Initializr API wrapper for Kotlin/JVM. This library provides the simplest DSL for initializing Spring Boot projects

StarkNet SDK for JVM languages (java, kotlin, scala)

☕ starknet jvm ☕ StarkNet SDK for JVM languages: Java Kotlin Scala Clojure Groovy Table of contents Documentation Example usages Making synchronous re

Kotools Assert is a lightweight assertions library for Kotlin

Kotools Assert is a lightweight assertions library for Kotlin

A lightweight Kotlin library which converts images to PixelArt in Android.
A lightweight Kotlin library which converts images to PixelArt in Android.

PixelArtImageView PixelArtImageView is a lightweight library used to convert standalone images into pixel art. The view extends ImageView behaviour an

Owner
Patrick
@scalagg, @lmaodesign.
Patrick
🍓CookHelper - food social network. The Api and Websocket are based on Ktor framework. Dependency injection with Koin library.

CookHelper [ ?? Work in Progress ?? ] CookHelper is a cross-platform application that will allow you to cook a delicious dish from an existing recipe

Arthur 11 Nov 9, 2022
Compile-time dependency injection for Kotlin Multiplatform

Kinzhal Kinzhal is a Kotlin Multiplatform library for compile-time dependency injection. The goal is to emulate basic features of Dagger to achieve si

Artem Daugel-Dauge 59 Dec 21, 2022
Minimalistic class proxy creator for Kotlin

reflektion Minimalistic class proxy creator for Kotlin. Reflektion allows you to create an implementation of an interface you provide containing proxy

Subham 6 Nov 11, 2022
A simple, lightweight, non-bloated redis client for kotlin and other JVM languages

rekt is a lightweight, non-bloated redis client, primarily written for the kotlin programming language, while also supporting other JVM-based languages, such as Java, Scala, and obviously way more.

Patrick 8 Nov 2, 2022
Kotlin dropwizard app running on Java 11. With Guice injection loaded.

hello world How to start the hello world application Run mvn clean install to build your application Start application with java -jar target/dropwizar

null 0 Nov 24, 2021
A Zero-Dependency Kotlin Faker implementation built to leave you fully satisfied

Satisfaketion A Zero-Dependency Kotlin Faker implementation built to leave you fully satisfied ?? ... With your fake data How to Install ?? Satisfaket

Ryan Brink 7 Oct 3, 2022
This lib is the framework for dependency tasks, specially for the asynchronous tasks.

DependencyTask This lib is the framework for dependency tasks, specially for the asynchronous tasks. Backgroud Image that there is a progress with som

null 1 May 6, 2022
My own approach to what I think an Android MVVM project with Clean Architecture should look like with Dagger-Hilt as Dependency Injector engine

MVVM Project Hilt Introducción Este proyecto es mi visión particular, ni mejor ni peor (sólo una más) que cualquier otra aproximación a lo que yo enti

Antonio Fdez. Alabarce 7 Dec 16, 2022
Utility library dedicated for functional & non-functional codebases to simplify modelling of success and failure responses for the JVM languages 🔀

Expressible Utility library, part of the panda-lang SDK, dedicated for functional codebases that require enhanced response handling. Express yourself

Panda 28 Nov 14, 2022
JVM Open Asset Import Library (Assimp)

assimp JVM porting of Assimp This port is being written trying to stick as much as possible close to the C version in order to: minimize maintenance t

null 83 Oct 30, 2022