romainbsl
04/15/2020, 12:30 PMjames
04/16/2020, 12:42 AMMyClass.getInstance()
.. I've now converted this to a Kodein singleton, however I'm wondering if there's still a way I can access it from one particular class without @Inject
? there's one particular class I don't really want to update because it is intertwined with a lot of other stuff and in the interest of time (and testing capacity) I would like to leave that class mostly untouched.
so most of the classes now just get MyClass
injected to them, but is there some way I can retrieve it from the other class I mentioned which I'd like to avoid making large changes to?sherry.yuan
04/21/2020, 12:25 AMmodule B
needs to use an instance from module A
is the best practice to import module A
into module B
? For example, subscribersModule
needs the retrofit instance from `networkingModule`:
val networkingModule = Kodein.Module("networking") {
bind<Retrofit>() with singleton {
Retrofit.Builder()
.baseUrl("<https://api.example.com/>")
.build()
}
}
val subscribersModule = Kodein.Module("subscribersModule") {
import(networkingModule)
bind<SubscribersService>() with singleton {
instance<Retrofit>().create(SubscribersService::class.java)
}
}
Pavel Arkhipov
04/27/2020, 2:50 PMUnable to instantiate activity ComponentInfo{uptop.me.testcoroutine/uptop.me.testcoroutine.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
Activity code:
class MainActivity : AppCompatActivity(), KodeinAware {
override val kodein by closestKodein(context = this)
private val viewModel: MainViewModel by kodein.instance<MainViewModelImpl>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
viewModel.doSomething()
}
}
Dependencies:
fun appModule(context: Context) = Kodein.Module("appModule") {
bind<MainInteractor>() with provider { MainInteractorImpl() }
bind<MainViewModel>() with provider { MainViewModelImpl(instance()) }
}
App:
class App: Application(), KodeinAware {
override val kodein: Kodein by Kodein.lazy {
import(androidXModule(this@App))
import(appModule(this@App))
}
}
Thanks in advance!mlykotom
04/28/2020, 8:08 AMContext
and Scope
, but I couldn’t find some good example how to achieve it. Could anyone point me to any article/tutorial/explanation of how to do it?
Thank you 🙂Nicolas
04/29/2020, 11:31 AMprivate val toolbarManager: ToolbarManager by instance() // the underlined error is on instance()
I can have no error with this code:
private val toolbarManager by instance<ToolbarManager>()
A while ago, perhaps before I have upgraded Android Studio and/or Kotlin and/or kodein, the first code didn't raise any error in Android Studio.
Does anybody have an explanation ?eygraber
06/01/2020, 7:17 AMeygraber
06/02/2020, 7:16 PMyshrsmz
06/09/2020, 11:04 AMInstance(erasedSet())
with instance()
in Kodein-DI 7.0?Joost Klitsie
06/15/2020, 3:21 PMMgj
07/02/2020, 9:38 AMExpression 'di' cannot be invoked as a function. The function 'invoke()' is not found
- Any ideas? Using kodein 7.0.0Mgj
07/02/2020, 10:16 AMkodein-generic
and kodein-erased
Alexander Minyaev
07/21/2020, 6:39 AM"org.kodein.di:kodein-di:7.0.0"
for jvm
"org.kodein.di:kodein-di-jvm:7.0.0"
for js
"org.kodein.di:kodein-di-js:7.0.0"
I see only for jvm and for js.Artem Kopan
08/21/2020, 8:05 AMJoost Klitsie
08/22/2020, 12:43 PMIvann Ruiz
08/31/2020, 4:15 PMcommonMain
the iOS dependency doesn't seem to be found...implementation("org.kodein.di:kodein-di:7.0.0")
tried following this post and I'm doing pretty much the same, noth sure if anyone has run into this same problem... thoughts?Peter
09/22/2020, 5:10 PMShawn Witte
09/26/2020, 2:07 AMDI
to provide platform-specific implementations.
Basically, I have an interface
in my common code that I have created a platform specific implementation for in JVM (no other platforms yet, since common/jvm is enough for my current level of multiplatform exploration). I originally decided to inject the platform specific code into the constructor without a framework: class SomeClass(val commonInterfaceName: CommonInterfaceName)
and then inject the implementation when I start the app from the JVM entry point.
I can do the same thing now by injecting a DI
instead, but I want to be able to create a DI
module that I know contains all of these bindings. I'm wondering if there is a standard way to ensure that the DI
being passed in has all of the necessary bindings (which I guess gets into a broader question of compile-time verification). Or if there is a way to
I'm not sure if what I'm saying is clear or not. Also, before you ask why I'm not using expect/actual
, the answer is because I don't know if/when I should. It seemed like interfaces would be more robust and provide for dependency injection (in the way that I was doing it, at least). I'm still trying to work out what multiplatform best practices look like.John O'Reilly
09/26/2020, 7:22 AM+--- org.kodein.db:kodein-db:0.2.0-beta FAILED
\--- org.kodein.db:kodein-db-serializer-kotlinx:0.2.0-beta
John O'Reilly
09/27/2020, 2:50 PMkodein-db
, am calling val db = DB.open("bikeshare_db")
but getting
org.kodein.db.leveldb.LevelDBException: NotFound: bikeshare_db/LOCK: No such file or directory
it seemed from https://docs.kodein.org/kodein-db/0.2.0/core/setup-database.html that the default is to create the database if it does not exist?aerialist
09/29/2020, 4:21 PMJohn O'Reilly
09/29/2020, 8:12 PMkodein-db
in a kotlin multiplatform project. https://docs.kodein.org/kodein-db/0.2.0/core/operations.html includes examples like
db.find<User>().all().models()
I'm not seeing models()
available here for some reasonrocketraman
09/30/2020, 1:45 PMapplicationContext
to initialize (SQLDelight android SqlDriver). Scopes seem the right way to do that, but I don't see anything like ApplicationScope available.rocketraman
09/30/2020, 9:28 PMWorker
as per https://stackoverflow.com/questions/59546159/kodein-injecting-into-workmanager -- however, as soon as I extend from DIAware
, I get e: java.lang.IllegalStateException: Backend Internal error: Exception during file facade code generation
at compile time. Any ideas?John O'Reilly
10/03/2020, 2:28 PMval networkList = cityBikesApi.fetchNetworkList().networks
networkList.forEach {
db.put(it)
}
but following does not work....should it?
db.put(networkList)
John O'Reilly
10/03/2020, 2:49 PMdb.find<Network>().all().useModels { it.toList() }
https://github.com/Kodein-Framework/Kodein-DB includes example of use of models()
but that's not resolving hereChristoph Flick
10/06/2020, 10:07 PMfun Application.main() {
di {
bind<SomeService>() with singleton { SomeService(environment.config) }
}
...
I use the service somewhere in the app, in the routes, etc.
My tests (kotest) look like that:
"A Request should do something" {
withServer {
val req = handleRequest {
uri = "/someroute"
}
req.requestHandled shouldBe true
req.response shouldHaveStatus HttpStatusCode.OK
}
}
withServer
is a wrapper for withTestApplication({ main() }, test)withTestApplication({ main() }, block)
My problem is that I currently need to test against a real database as I don't get the DI mock to work.
Any hints for me here?
Thanks!nrobi
10/08/2020, 7:30 AMTucker Barbour
10/23/2020, 7:58 AMDavid Hadley
10/24/2020, 12:33 PM