salomonbrys
01/07/2019, 4:21 PMian.shaun.thomas
02/06/2019, 6:31 PMyshrsmz
02/20/2019, 1:45 AMlogger
as CommonLogger.
And in general depending on concrete class is anti-pattern, so if I were you I would bind to CommonLogger
in JVM.Jorge Castillo
03/12/2019, 10:44 AMjudrummer
04/01/2019, 6:12 PMJoakimForslund
04/03/2019, 9:26 AMoverride val kodein = Kodein {
import(sdkModule)
}
which sets up all the binds. Do each class using those binds also need to implement the above snippet to use them? Or is it enough just to do val nameOfVar by instance() ?mben
04/10/2019, 8:50 AMmkobit
04/12/2019, 6:51 PMallInstances()
) regardless of tag?
we have an application that has multiple ServerInterceptor
that gets added to the server
right now we have to bind it in basically 2 places
1. where we want to introduce and configure the ServerInterceptor
implementation
2. in the place where we build the Server
instance and provide the multiple ServerInterceptor
it doesn't look like i can have multiple bindings of the same type (even if in separate kodein modules)
for example:
interface MyInterface
class Impl1 : MyInterface
class Impl2(val s: String) : MyInterface
fun main() {
val kodein = Kodein {
constant(tag = "String") with "stringy"
bind<MyInterface>() with singleton { Impl1() }
bind<MyInterface>() with singleton { Impl2(instance(tag = "String")) }
}
val all = kodein.direct.allInstances<MyInterface>()
println(all)
}
fails at bin building time with org.kodein.di.Kodein$OverridingException: Binding bind<MyInterface>() with ? { ? } must not override an existing binding.
adding tags
bind<MyInterface>(tag = "1") with singleton { Impl1() }
bind<MyInterface>(tag = "2") with singleton { Impl2(instance(tag = "String")) }
prints an empty list []
i've seen the inSet()
and bind() from setBinding<ServerInterceptor>()
, but that feels a bit odd, because then each module needs to also use inSet()
on the binding
what is the best way to handle this if i'm trying to keep the modules separate?streetsofboston
04/16/2019, 5:04 PMjava.lang.RuntimeException: Unable to start activity ComponentInfo{com.wecenergygroup.wps.debug/com.wec.weenergies.screens.landing.LandingActivity}: org.kodein.di.Kodein$NotFoundException: 3 bindings found that match bind<Context>() with ?<LandingActivity>().? { ? }:
module Context {
bind<Context>() with singleton { Application }
}
module WeEnergiesApplication {
bind<WeEnergiesApplication>() with singleton { WeEnergiesApplication }
}
module androidModule {
bind<Application>() with provider { Application }
}
The first two are under our app’s control, the last one is from Kodein’s androidModule
.
What would be the ‘best’ way to solve this ambiguity? Using ‘sub-type’ bindings or is there a less verbose way?hamutarto
04/23/2019, 12:36 PMorg.kodein.di.Kodein$NotFoundException: No binding found for bind<SharedPreferences>() with ? { ? }
Available bindings for this type:
module androidModule {
bind<SharedPreferences>() with contexted<Context>().provider { SharedPreferences }
bind<SharedPreferences>() with contexted<Context>().factory { String -> SharedPreferences }
}
Registered in this Kodein container:
..
max.denissov
04/24/2019, 3:25 PMJan Stoltman
05/07/2019, 3:22 PMCould not find org.kodein.di:kodein-di-erased:6.2.0
It used to work just fine with 6.1.0. Anybody has any idea what might be the cause?Chih
05/16/2019, 2:30 AMChih
05/18/2019, 9:12 PMKodein.Module(name = "web") {
bind<Controller>(tag = "health") with singleton { HealthController(instance()) }
bind<Controller>(tag = "user") with singleton { UserController(instance()) }
bind() from singleton { Server(allInstances<Controller>()) }
}
class Server(private val routes: List<Controller>) { ... }
When I debug routes
, it is an empty list.
Thanks in advance!igor.wojda
05/24/2019, 3:27 PMkodein
inside ViewHolder
?
class SomeViewHolder(
view: View,
val view: View,
private val data: Boolean,
) : RecyclerView.ViewHolder(view) {
) : RecyclerView.ViewHolder(view), KodeinAware {
override val kodein by view.kodein()
private val formatter: CurrencyFormatter by instance()
….
}
Joan Colmenero
06/03/2019, 2:45 PMDagger2
I had it divided by modules and I see this like a dirty way to do the dependency injection, is there any other way to do it cleaner?yahyabayramoglu
06/18/2019, 4:12 PMJoan Colmenero
07/06/2019, 7:14 PM@Database(entities = [Something::class], version = 1, exportSchema = false)
abstract class MyDatabase : RoomDatabase() {
abstract fun myDao(): MyDao
companion object {
@Volatile
private var INSTANCE: MyDatabase? = null
fun getInstance(context: Context): MyDatabase =
INSTANCE ?: synchronized(this) {
INSTANCE ?: buildDatabase(context).also { INSTANCE = it }
}
private fun buildDatabase(context: Context) =
Room.databaseBuilder(
context.applicationContext,
MyDatabase::class.java, "sample_db"
)
.allowMainThreadQueries()
.build()
}
}
Evan Bennett
07/09/2019, 6:41 AMhamutarto
07/12/2019, 7:30 PMorg.kodein.di.Kodein$NotFoundException: No binding found for bind<SharedPreferences>() with ? { ? }
Available bindings for this type:
module androidModule {
bind<SharedPreferences>() with contexted<Context>().factory { String -> SharedPreferences }
bind<SharedPreferences>() with contexted<Context>().provider { SharedPreferences }
}
Registered in this Kodein container:
module analyticsModule {
bind<Analytics>() with singleton { AnalyticsImpl }
}
....
module apiM
I tried to solve it by manually bind SharedPreferences, without any luck
bind<SharedPreferences>() with singleton { PreferenceManager.getDefaultSharedPreferences(instance()) }
but what I eventually do (as I need Android Context as well for injection) is to use androidXmodule in the Application object. However the issue is still coming
override val kodein = Kodein.lazy {
import(androidXModule(this@MainApplication))
import(generalModule)
import(repositoryModule)
import(viewModelModule)
import(appSettingsModule)
import(apiModule)
import(useCaseModule)
import(analyticsModule)
import(locationModule)
import(dataSourceModule)
}
Please help me! I can’t find the solutionJan Stoltman
07/24/2019, 8:10 AMIvan
07/24/2019, 4:24 PMn0rtan
07/24/2019, 7:50 PMn0rtan
07/24/2019, 7:59 PMGiovani Guerra
08/01/2019, 6:56 PMAlbert
08/23/2019, 8:20 AMbind<Action>(tag = "ActionImpl2") with singleton { ActionImpl2() }
bind<Action>(tag = "ActionImpl2") with singleton { ActionImpl2() }
bind<Action>() with singleton {
CompositeAction(
allInstances<Action>()
)
}
Problem here is that allInstances<Action>()
is causing recursive error, probably because this is lazy loaded. Is it possible to invoke allInstances<Action>()
in such a way that it will exclude it own bind and only loads the Action
instances with a tag
? Preferably I don't want to eager load.ushort
09/03/2019, 1:36 AMjudrummer
09/11/2019, 5:33 PMPaulus Limma
09/16/2019, 5:37 AMjames
10/03/2019, 3:46 AMjames
10/03/2019, 3:46 AMsalomonbrys
10/04/2019, 8:52 AMghedeon
10/06/2019, 8:16 AMsalomonbrys
10/07/2019, 9:02 AM