https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
kotlin-inject
  • e

    evant

    06/14/2021, 4:06 PM
    This sounds very similar to 'find an impl from interface' except for functions. One thing I want to point out is that 'find all the things that impl something' is an expensive compile-time operation and would like to avoid it if possible.
    d
    • 2
    • 1
  • e

    evant

    06/14/2021, 4:37 PM
    my understanding for anvil would be from
    interface AppComponent
    
    @ContributesTo(AppComponent::class)
    abstract class MyComponent1
    
    @ContributsTo(AppComponent::class)
    abstract class MyComponent2
    generate
    @Component
    abstract AppComponentImpl : AppComponent, MyComponent1, MyComponent2
    which... I'm not sure is worth it? Maybe I'm missing use-cases here.
    j
    • 2
    • 7
  • e

    evant

    06/15/2021, 1:16 PM
    It's using a map to cache the object in the component when you scope it.
    d
    • 2
    • 4
  • s

    saket

    10/27/2021, 10:56 PM
    I was able to reproduce the
    Unresolved reference
    bug in your sample: https://github.com/evant/kotlin-inject-samples/pull/3
    e
    • 2
    • 13
  • s

    saket

    11/06/2021, 4:27 AM
    I'm wondering whether https://github.com/evant/kotlin-inject/pull/162 is available in
    0.3.8-SNAPSHOT
    yet
    e
    • 2
    • 2
  • s

    saket

    11/06/2021, 6:06 AM
    q: are these two providers not supposed to be equivalent?
    protected val RealHttp.bind: Http
      @Provides 
      @SomeScope 
      get() = this
    @Provides
    @SomeScope
    fun http(real: RealHttp): Http = real
    e
    • 2
    • 6
  • s

    saket

    11/07/2021, 2:52 AM
    unfortunately, ksp's lack of v1.0.1 release with kotlin 1.5.31 is blocking me from compiling my project on android
    e
    • 2
    • 2
  • p

    Paul Woitaschek

    11/10/2021, 1:05 PM
    I'm missing dagger modules in kotlin-inject. In theory it might work to create fake components as interfaces and let your root component implement it, but that causes issues because interfaces can only have public members. And most of the times in a gradle module I module internal dependencies that are used to create an object
    e
    • 2
    • 1
  • p

    Paul Woitaschek

    11/10/2021, 2:25 PM
    Uh and the other big thing is freezing. I'm trying to migrate a manual service locator to kotlin-inject and it blows up because we need to freeze our di entry point and as LazyMap is using mutable state that's not wrapped in an IsoMutableMap that makes kotlin-inject effectively main thread limited 😕
    e
    • 2
    • 3
  • e

    eygraber

    11/11/2021, 4:51 AM
    I'm testing a very simple sample with kotlin-inject, and everything works including the codegen, however I can't reference any of the generated classes. For example if I have a
    MainComponent
    there is a generated
    fun KClass<MainComponent>.create()
    however I can't reference it from my code.
    e
    • 2
    • 2
  • s

    saket

    11/12/2021, 5:26 AM
    I'm noticing that stale generated code for classes that no longer exist aren't removed by kotlin-inject. Is this something that ksp is supposed to handle?
    p
    e
    • 3
    • 4
  • e

    eygraber

    11/23/2021, 5:52 AM
    Is it possible to have a scoped child component that narrows the scope for a dependency? Example in thread.
    e
    • 2
    • 12
  • d

    dave08

    12/16/2021, 1:50 PM
    Solved... it was because in Android there's debug and release using the assemble task... and for some reason it looks at both even though I have only the debug one in the source set instruction...
    e
    • 2
    • 1
  • e

    evant

    01/11/2022, 3:02 PM
    yeah the types have to match exactly, you can do
    @Provides @IntoSet fun provideFoo(): () -> Foo = { FooImpl() }
    d
    • 2
    • 12
  • e

    evant

    01/11/2022, 3:06 PM
    For a combination between maps and sets, you could wire something together but it would be a bit complicated
    typealias Foo1 = Foo
    typealias Foo2 = Foo
    
    @Provides @IntoSet
    fun foo1ForSet1(): Foo1 = ...
    @Provides @IntoSet
    fun foo2ForSet1(): Foo1 = ...
    @Provides @IntoSet
    fun foo1ForSet2(): Foo2 = ...
    @Provides @IntoSet
    fun foo2ForSet2(): Foo2 = ...
    
    @Provides @IntoMap
    fun fooSet1(set: Set<Foo1>): Pair<String, Set<Foo>> = "one" to set
    @Provides @IntoMap
    fun fooSet2(set: Set<Foo2>): Pair<String, Set<Foo>> = "two" to set
    d
    • 2
    • 9
  • d

    dave08

    01/17/2022, 4:53 PM
    @evant Do you have any plans to add something like Dagger's
    fun inject(someActivity: SomeActivity)
    ...? It's SO MUCH nicer than having to do the trick in the Android docs on kotlin-inject's Github repo...
    e
    p
    • 3
    • 9
  • e

    eygraber

    02/22/2022, 6:11 AM
    Is it possible to add a
    @Inject
    to a typealias? My use case is where I have a type that I want to use in two different scopes:
    class Foo
    
    @AppScope
    @Inject
    typealias AppFoo = Foo
    
    @ScreenScope
    @Inject
    typealias ScreenFoo = Foo
    Currently I have to use provider functions, which is a lot more verbose, especially since I now need a component for those function:
    @Component
    abstract class FooComponent {
      @AppScope @Provides fun provideAppFoo() = AppFoo()
      @ScreenScope @Provides fun provideScreenFoo() = ScreenFoo()
    }
    (this example is contrived, but I do have an actual use case for something like this)
    e
    • 2
    • 3
  • e

    eygraber

    02/27/2022, 6:02 AM
    Is it OK to rely on a child component to provide a dependency? For example:
    class ResolverWrapper(val resolver: ContentResolver)
    
    @Component abstract class ParentComponent {
      @Provides fun providesContentResolve(context: Context) = context.contentResolver
    }
    
    @Component abstract class ChildComponent(
      @Component val parent: ParentComponent,
      @get:Provides val context: Context
    ) {
      abstract val wrapper: ResolverWrapper
    }
    The above works, but is it OK to rely on this behavior?
    e
    • 2
    • 6
  • h

    humblehacker

    03/16/2022, 8:05 PM
    Does anyone have a sample to share of injecting a view model into an
    @Composable
    function? If I do it as I would for a non-composable function, I get a new view model every time my view is recomposed.
    e
    • 2
    • 10
  • h

    humblehacker

    04/08/2022, 12:54 AM
    Anyone have a sample of a modular Android app using kotlin-inject, with different modules defining their own
    @Components
    forming a tree of dependencies? I'm modularizing an app previously set up with kotlin-inject, and I'm running into issues. I'm hoping that by looking at a working example I can avoid having to ask a bunch of questions.
    m
    • 2
    • 2
  • e

    evant

    04/21/2022, 8:55 PM
    Not currently for simplicity's sake. Did look at a bit but haven't found a way that has enough benefits to be worth saving just a line of code. If you are binding an impl to an interface the it's probably because you want to be using different impls in different places so you need to tie it to something, it can't just be global. Putting it in a component is a natural way to do that as you can have different components provide different impls for the same interface. Sure you could reverse it and do something like
    @Binds(in = AppComponent::class)
    @Inject
    class MyImpl : Impl
    but it just feels like shuffling things around? It's also nice to have them all in one place so you can override them all for tests (a common usecase for having multiple impls for an interface).
    m
    • 2
    • 2
  • e

    evant

    06/09/2022, 5:44 PM
    Hey question, how would people feel about removing the kapt back-end? It costs quite a bit to maintain and limits certain features which can only be done in ksp (like annotating properties). I'm curious if people are even using it?
    👍 2
    p
    • 2
    • 2
  • p

    Paul Woitaschek

    07/19/2022, 11:31 AM
    @evant I noticed that kotlin-inject doens’t have any synchronization logic for native. This is quite error prone as objects might be created multiple times though they are scoped. What do you think about making use of a lock on native like implemented here? https://github.com/InsertKoinIO/koin/blob/1326329060e6b923f9a54873178e55cdddc4d99e/core/koin-core/src/nativeMain/kotlin/org/koin/mp/KoinPlatformTools.kt#L29
    e
    • 2
    • 2
  • p

    Paul Woitaschek

    07/23/2022, 3:25 PM
    @evant WDYT about a ContributesXYZ functionallity in kotlin-inject, similar to what Anvil does? https://github.com/square/anvil I wouldn’t want to miss it as it really decouples the binding boilerplate, especially with multibindings.
  • e

    evant

    08/03/2022, 4:49 AM
    Just released 0.5.0! https://github.com/evant/kotlin-inject/releases/tag/v0.5.0
    p
    d
    e
    • 4
    • 29
  • p

    Paul Woitaschek

    08/03/2022, 3:07 PM
    @evant What do you think about adding an explicit @Assisted annotation? My developers get extremely confused with the implicit “last arguments in the right order” approach.
  • p

    Paul Woitaschek

    08/03/2022, 3:09 PM
    Second thing, slightly related. The typealias logic is also confusing everyone. Also it seems that it’s abusing language features: https://kotlinlang.org/docs/type-aliases.html
    Type aliases do not introduce new types. They are equivalent to the corresponding underlying types.
    I think a dedicated Qualifier annotation would make things simpler to everyone.
    e
    • 2
    • 11
  • e

    evant

    08/04/2022, 6:05 PM
    Btw @eygraber about that parent/child injection change. I had originally had a more permissive check to just try to find potential leaks when using scopes, but I ran into a few problems with it. 1. It had some holes, you could easily get around it by inserting an unscoped dep between 2 scoped ones and it would compile but still leak. I could try to fix it but I was worried that I would have to keep chasing issues like that. 2. Which leads to another problem which is the logic here was subtle and I think it would be hard to understand what is allowed vs what is not, vs the simpler model that you can only go 'up' the graph to parents and not back down. 3. I checked dagger and verified that it behaves the same way with it's subcomponents. Just letting you know how I landed where I did.
    e
    • 2
    • 1
  • e

    evant

    08/05/2022, 9:44 PM
    https://github.com/evant/kotlin-inject/issues/164#issuecomment-1206903609
  • e

    evant

    08/05/2022, 9:46 PM
    Also 0.5.1 is now released which fixes the artifact resolution issue on multiplatfom with 0.5.0 😅
Powered by Linen
Title
e

evant

08/05/2022, 9:46 PM
Also 0.5.1 is now released which fixes the artifact resolution issue on multiplatfom with 0.5.0 😅
View count: 2