kluck
04/12/2018, 7:07 AMclass BatteryBroadcastReceiver : KodeinAware, BroadcastReceiver() {
override lateinit var kodein: Kodein
private val myBinding: Stuff by instance()
override fun onReceive(context: Context?, intent: Intent?) {
if (!::kodein.isInitialized) {
kodein = (context as KodeinAware).kodein
}
...
}
}
salomonbrys
04/12/2018, 12:23 PMorg.kodein.di.*
- Introducing subtype bindings, which allow to register a parent type and the a binding factory that will provide a binding for each new subtype of this parent type.
As usual, everything is in the documentation (http://kodein.org/Kodein-DI/) and changelog (https://github.com/Kodein-Framework/Kodein-DI/blob/master/CHANGELOG.md).
Second, announcing the Kodein Framework (http://kodein.org). It does really not exist yet: Kodein-DI is (at the moment) the only released component of the framework. This framework will propose various components that are focused on multi-plateform development (JVM/Android/JS/Native/iOS).
Note that each component will be usable by its own and that Kodein-DI, as well as other components, will continue to also be focused on the JVM and Android. Being multi-platform does NOT mean sacrificing JVM only goodies. Kodein-DI 5 includes multiple features that are available only to JVM & Android, and those features will continue to be supported.
Some components of the framework (such as Kodein-JSON) will be focused exclusively on multi-platform and some other (such as Kodein-DI) won't. The choice is made based on the usefulness of the component outside of the multi-platform ecosystem.
The framework itself will aim to provide a full ecosystem to easily create business code, modules and architecture to be shared between platforms. In term, applications that are developed with the Kodein Framework should contain 60% to 80% of shared code between platforms.
Finally, to support all of that, I'm very happy to announce the Kodein company: http://kodein.net .
This company, based in France but active in all Europe, develops three major axes:
- Kotlin consultancy & development services.
- Kotlin training & migration programs.
- Kodein framework development & support.
If you would like to work or contract with us, feel free to contact me at salomon@kodein.net.
Note that the Kodein framework in general and the Kodein-DI library in particular will remain fully Open-Source and that the community will continue to be supported. I am Open-Source at heart and the company we are building is too. We plan to monetize through services: consultancy, SLA support, training, development, etc.
All of this is still in early stages.
In the meantime, I hope you enjoy Kodein-DI 5.0.0 😉
Salomon.streetsofboston
04/16/2018, 4:40 PMdave08
04/22/2018, 5:17 PMKodein.Module
access the bindings in another imported module, or only the importing Kodein
has access to all the module's bindings? If the latter then a module will have to be a fun
that accepts all dependencies needed from other modules, or does it also have to import the module to use it...?poohbar
05/02/2018, 6:12 PMIn DI, each business unit will have dependencies. Those dependencies should (nearly almost) always be interfaces.So I am wondering if Kodein is a good choice for me if I don't have silly interfaces for every single dependency.
leosan
05/03/2018, 11:37 AMclass Foo(view:ViewFoo)
And a Kodein.Lazy with this binding
bind<Foo>() with scopedSingleton(androidFragmentScope) {
Foo(it)
}
and on my `MyFragment(), ViewFoo`I’m retrieving like this
val foo by kodein.with(this).instance<Foo>()
But then it throws this error
No factory found for bind<Foo>() with ? { MyFragment -> ? }
Registered in Kodein:
bind<Foo>() with scopedSingleton(androidFragmentScope) { Fragment -> Foo }
salomonbrys
05/09/2018, 8:16 AMoverride val kodein = Kodein.lazy {
extend(closestKodein())
import(menuViewModelModule(this@MenuFragment))
}
kluck
05/18/2018, 5:45 AMviewModel: MainViewModel by kodein.instance()
will try to retrieve an unscoped MainViewModel (and none are defined in your bindings!)streetsofboston
05/22/2018, 8:29 PMval myInstanceOfT by kodin.instance<T>(tag)
or val myInstanceOfT = kodein.direct.instance<T>(tag)
avolkmann
05/25/2018, 5:55 PMbdavisx
05/27/2018, 10:02 PMdave08
05/30/2018, 1:27 PMbind<ProgressNotifier>() with factory { id: Int, iconRes: Int, title: String ->
ProgressNotifierImpl(instance(), id, iconRes, title)
}
bind() from singleton { InstallationNotifier(factory() as ((Int,Int,String) -> ProgressNotifier)) }
But idea tells me that type inference failed for A
on factory()
call in the InstallationNotifier
constructor... how could I acheive this? the constructor takes: val progressNotifierFactory: (id: Int, iconRes: Int, title: String) -> ProgressNotifier
streetsofboston
06/12/2018, 12:12 PMuli
06/12/2018, 7:45 PMyccheng
06/21/2018, 4:15 PMeygraber
07/06/2018, 9:21 PMabstract class MyFragment: Fragment, KodeinAware {
private val parentKodein: Kodein by closestKodein()
override val kodein = Kodein {
}
// contrived example, but whatever
// doesn't work because activity is null
private val presenter: MyActivityPresenter by on(context = activity).instance()
// used to be able to do:
// private val presenter: MyActivityPresenter by with { activity }.instance()
}
Vinicius Carvalho
07/10/2018, 2:18 PMkodein.allInstances
, is there a way to find them by name? I'm a 14 yr old Spring user, so I'm kinda used to that 😉rocketraman
07/13/2018, 4:10 PMjudrummer
07/18/2018, 6:49 PMAndreas Sinz
07/19/2018, 7:36 PMJorge Castillo
08/17/2018, 5:30 PMeygraber
08/24/2018, 1:36 AM(Long) -> String
, but when I inject it, I get a (String) -> Request)
which is obviously not good.salomonbrys
10/02/2018, 4:00 PMsalomonbrys
10/17/2018, 5:58 PMAppSessionScope
and UserSessionScope
implementation. I suppose they are using MultiItemObjectRegistry
? There's a clean
method on it, to "clear" the registry, which makes all objects go out of scope.
However, this might not be necessary if the registry is only "held" by an object that goes out of scope. GC can take care of that.
Using a WeakContextScope
can also be a way to not manually clean the registry.dave08
10/25/2018, 4:33 PMinstance()
and factory()
in the bindings... it greatly reduces typing but sometimes leaves dangling dependencies...salomonbrys
11/12/2018, 5:57 PMScope
interface, so it is much (much) more easier to create your own scopes. More in the doc: http://kodein.org/Kodein-DI/?6.0/core#scope-creation
Of course, the changelog is here: https://github.com/Kodein-Framework/Kodein-DI/blob/6.0/CHANGELOG.md
Also, if you want to see what's in my mind for the future, you can do so here: https://github.com/Kodein-Framework/Kodein-DI/blob/6.0/TODO.md
Finally, please note that due to this sync issue with JCenter, I haven't updated master yet. The default documentation is therefore still showing Kodein 5.3.
The updated documentation for version 6.0.0 is here: http://kodein.org/Kodein-DI/?6.0judrummer
11/19/2018, 7:55 AMDavid Fallah
11/21/2018, 9:21 AMFoo<T>
and resolve Foo<Int>
or Foo<String>
.igor.wojda
11/22/2018, 11:06 PM5.3.0
while all docs are referring to 6.0.0
. 5.3.0
works fine. When I try to use 6.0.0
dependencies are resolved properly but some of the stuff is missing eg. KodeinAware
interface.
should I stick with 5.3.0
or I should use 6.0.0
and do something differently?
My dependencies
import "org.kodein.di:kodein-di-generic-jvm:5.3.0"
import "org.kodein.di:kodein-di-framework-android-x:5.3.0"
igor.wojda
11/24/2018, 7:00 PMigor.wojda
11/24/2018, 7:00 PMstreetsofboston
11/24/2018, 11:04 PMid
using the Intent
that starts the Activity. Then when creating an instance of your AlbumDetailsViewModel, provide the id
by doing intent.getStringExtra
igor.wojda
11/25/2018, 9:01 AMViewModel.Factory
). It would be preferable to inject this factory into activity, however factory requires a bit of configuration (album Id) before it is constructed 🤔streetsofboston
11/25/2018, 5:25 PMbindViewModel
, that takes a KodeinAware
as a second receiver, a lambda as a parameter, and uses a custom ViewModel.Factory
for its implementation. The lambda will return a new ViewModel
when it is called. This allows for arguments (eg the intent extra) to be provided.igor.wojda
11/26/2018, 9:21 AM