{"id":15294686,"url":"https://github.com/misfitlabsdev/kotlin-guice","last_synced_at":"2025-06-13T13:09:08.892Z","repository":{"id":44067650,"uuid":"94452776","full_name":"misfitlabsdev/kotlin-guice","owner":"misfitlabsdev","description":"Guice DSL extensions for Kotlin","archived":false,"fork":false,"pushed_at":"2023-06-26T14:43:13.000Z","size":385,"stargazers_count":66,"open_issues_count":4,"forks_count":12,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T14:53:48.299Z","etag":null,"topics":["dependency-injection","guice","kotlin"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/misfitlabsdev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-06-15T15:23:51.000Z","updated_at":"2024-07-07T17:10:29.000Z","dependencies_parsed_at":"2025-04-13T14:53:45.476Z","dependency_job_id":"7aafaba2-0595-4dfa-80d5-45837f771f49","html_url":"https://github.com/misfitlabsdev/kotlin-guice","commit_stats":null,"previous_names":["authzee/kotlin-guice"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/misfitlabsdev/kotlin-guice","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/misfitlabsdev%2Fkotlin-guice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/misfitlabsdev%2Fkotlin-guice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/misfitlabsdev%2Fkotlin-guice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/misfitlabsdev%2Fkotlin-guice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/misfitlabsdev","download_url":"https://codeload.github.com/misfitlabsdev/kotlin-guice/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/misfitlabsdev%2Fkotlin-guice/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259650956,"owners_count":22890385,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dependency-injection","guice","kotlin"],"created_at":"2024-09-30T17:06:00.936Z","updated_at":"2025-06-13T13:09:08.838Z","avatar_url":"https://github.com/misfitlabsdev.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"kotlin-guice\n============\n\nGuice extensions for Kotlin. This provides extension wrappers and extension methods for providing a better Guice DSL experience from Kotlin. It takes advantage of reified types to reduce class references like `bind(MyResource::class.java)` to `bind\u003cMyResource\u003e()`.\n\n## Download\n\nDownload the latest JAR via Maven:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003edev.misfitlabs.kotlinguice4\u003c/groupId\u003e\n  \u003cartifactId\u003ekotlin-guice\u003c/artifactId\u003e\n  \u003cversion\u003e3.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nor Gradle:\n\n```gradle\ncompile 'dev.misfitlabs.kotlinguice4:kotlin-guice:3.0.0'\n```\n\n## Getting Started\n\n### KotlinModule\n\nUse `KotlinModule` for Guice modules instead of `AbstractModule` to take advantage of the enhanced Kotlin Guice DSL. \n\n```kotlin\nimport dev.misfitlabs.kotlinguice4.KotlinModule\n\nclass MyModule : KotlinModule() {\n    override fun configure() {\n        bind\u003cService\u003e().to\u003cServiceImpl\u003e().`in`\u003cSingleton\u003e()\n        bind\u003cPaymentService\u003cCreditCard\u003e\u003e().to\u003cCreditCardPaymentService\u003e()\n        bind\u003cCreditCardProcessor\u003e().annotatedWith\u003cPayPal\u003e().to\u003cPayPalCreditCardProcessor\u003e()\n    }\n}\n```\n\nThe `KotlinPrivateModule` can also be used if only some bindings need to be exposed.\n\n```kotlin\nimport dev.misfitlabs.kotlinguice4.KotlinPrivateModule\n\nclass MyPrivateModule : KotlinPrivateModule() {\n    override fun configure() {\n        bind\u003cService\u003e().to\u003cServiceImpl\u003e().`in`\u003cSingleton\u003e()\n        bind\u003cPaymentService\u003cCreditCard\u003e\u003e().to\u003cCreditCardPaymentService\u003e()\n        bind\u003cCreditCardProcessor\u003e().annotatedWith\u003cPayPal\u003e().to\u003cPayPalCreditCardProcessor\u003e()\n        \n        expose\u003cPaymentService\u003cCreditCard\u003e\u003e()\n    }\n}\n```\n\n### Injector\n\nThe Guice injector has been enhanced with extension methods to make direct use of the injector better from Kotlin.\n\n```kotlin\nimport dev.misfitlabs.kotlinguice4.annotatedKey\nimport dev.misfitlabs.kotlinguice4.getInstance\n\nfun main(args: Array\u003cString\u003e) {\n  val injector = Guice.createInjector(MyModule(), MyPrivateModule())\n  \n  val paymentService = injector.getInstance\u003cPaymentService\u003cCreditCard\u003e\u003e()\n  \n  // Use the annotatedKey to get an annotated instance\n  val payPalProcessor = injector.getInstance(annotatedKey\u003cCreditCardProcessor, PayPayl\u003e())\n}\n```\n\n### Key and TypeLiteral\n\nPackage level functions are included to enhance creating `Key` and `TypeLiteral` instances from kotlin.\n\n```kotlin\nimport dev.misfitlabs.kotlinguice4.annotatedKey\nimport dev.misfitlabs.kotlinguice4.key\nimport dev.misfitlabs.kotlinguice4.typeLiteral\n\nval key = key\u003cString\u003e()\nval annotatedKey = annotatedKey\u003cString, SomeAnnotation\u003e()\nval sameAnnotatedDifferentKey = annotatedKey.getType\u003cLong\u003e()\n\nval listType = typeLiteral\u003cPaymentService\u003cCreditCrd\u003e\u003e()\n```\n\n### Multibindings\n\nAs of version 1.4.1 the kotlin-guice-multibindings module is gone and the functionality has been merged into kotlin-guice.\n\n#### Usage\n\n```kotlin\nval multibinder = KotlinMultibinder.newSetBinder\u003cSnack\u003e(kotlinBinder)\nmultibinder.addBinding().to\u003cTwix\u003e()\n\nval mapbinder = KotlinMapBinder.newMapBinder\u003cString, Snack\u003e(kotlinBinder)\nmapbinder.addBinding(\"twix\").to\u003cTwix\u003e()\n```\n\nWith Guice 4.2+, scanning for methods with the multibinding annotations `ProvidesIntoSet`, `ProvidesIntoMap`, and `ProvidesIntoOptional` is enabled by default. However, the default scanner only provides bindings for Java collection types. In order to get bindings for Kotlin collection types, install the `KotlinMultibindingsScanner`.\n\n```kotlin\ninstall(KotlinMultibindingsScanner.asModule())\n```\n\n## License\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n        http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmisfitlabsdev%2Fkotlin-guice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmisfitlabsdev%2Fkotlin-guice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmisfitlabsdev%2Fkotlin-guice/lists"}