https://github.com/jlleitschuh/kotlin-guiced
Convenience Kotlin API over the Google Guice DI Library
https://github.com/jlleitschuh/kotlin-guiced
dependency-injection google google-guice guice java jvm kotlin
Last synced: 3 months ago
JSON representation
Convenience Kotlin API over the Google Guice DI Library
- Host: GitHub
- URL: https://github.com/jlleitschuh/kotlin-guiced
- Owner: JLLeitschuh
- License: mit
- Created: 2017-06-01T21:50:10.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-01-03T18:36:28.000Z (almost 7 years ago)
- Last Synced: 2025-03-17T00:41:29.278Z (7 months ago)
- Topics: dependency-injection, google, google-guice, guice, java, jvm, kotlin
- Language: Kotlin
- Homepage:
- Size: 229 KB
- Stars: 18
- Watchers: 3
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Kotlin Guiced
[](https://travis-ci.org/JLLeitschuh/kotlin-guiced)
[  ](https://bintray.com/jlleitschuh/maven-artifacts/kotlin-guiced/_latestVersion)A Kotlin API wrapper over the [Google Guice](https://github.com/google/guice) Dependency Injection library.
This library aims to encourage the use of Guice with Kotlin by simplifying the Guice API so it is more
fluent in the Kotlin programming language.## NOTE:
Project is in very early stage of development. I plan to add helper functions as needed in a parallel cooperate internal
project and this project it may not comprehensively cover all of the methods out of the box.## Examples:
### TypeLiteral
Because of java type erasure, Guice uses some strange java syntax to preserve type at runtime.
Many of these problems have been solved by Kotlin using inline functions with `reified` types.In java you can declare a type literal with:
```java
final TypeLiteral> someLiteral = new TypeLiteral>() {}
```
In Kotlin this syntax becomes even more verbose requiring more characters to write.
```kotlin
val someLiteral = object : TypeLiteral>() {}
```
This library provides helpers like the one below that is much cleaner to read.
```kotlin
val someLiteral = typeLiteral>()
```### Guice Modules
Creating a module in Java requires quite a bit of extra boilerplate.
```java
public class MyModule extends AbstractModule {
@Override
void configure() {
bind(SomeService.class).to(SomeServiceImpl.class);
}
}class Main {
public static void main(String... args) {
final Injector injector = Guice.createInjector(new MyModule());
}
}
```
This is the equivalent in Kotlin:
```kotlin
fun main(vararg args: String) {
val myModule = module {
bind(SomeService::class).to(SomeServiceImpl::class)
// Or, even simpler with reified generics
bind().to()
}
val injector = Guice.createInjector(myModule)
}
```The library also defines a simple way of declaring private modules:
```kotlin
fun main(vararg args: String) {
val privateModule = privateModule {
bind().to()
expose()
}
val injector = Guice.createInjector(privateModule)
}
```## Project Structure
The intention is to structure this project such that Guice Core and each of it's respective extensions will
be in their own projects. The reasoning being that a library consumer can choose to depend upon only the Guice
extensions they need an not get a transitive dependency on a Guice extention they don't need.## Developers
### Requirements
Requires JDK 8 installed (Kotlin Compiler compiles to JDK 6 bytecode but requires JDK 8 to run).### Building
This project uses Gradle to build/test/deploy code.
Run `./gradlew tasks` to se the various tasks this project supports.