Skip to content

tothlp/beanject

Repository files navigation

Beanject

Beanject is a very simple dependency injection utility for Kotlin. It allows you to manage your application's components in an easy and decoupled manner.

Installation

To use Beanject in your project, add the following to your build.gradle.kts file:

dependencies {
    implementation("hu.tothlp:beanject:1.0")
}

Usage

Here are some basic examples of how to use Beanject:

Registering a Bean

data class TestBean(val testString: String)

val mockBean = TestBean("Test String")
Beanject.beans {
    bean("testBean") { mockBean }
}

// Beanject can be omitted, if the function is imported:
beans {
	bean("testBean") { mockBean }
}

Retrieving a Bean by Name

val retrievedBean = getBeanByName("testBean")

Retrieving a Bean by Type

val retrievedBean = getBean<String>()