salomonbrys
03/09/2018, 3:33 PMbind<ViewModel>() with multiton(ref = weakReference) { activity: Activity -> ViewModelProviders.of(activity).get(MyViewModel::class.java) }
, and retrieve with val view: MyViewModel by instance<ViewModel>(arg = this) as MyViewModel
.
2. Use a context singleton : bind<ViewModel>() with singleton(scope = androidScope<Activity>()) { ViewModelProviders.of(context).get(MyViewModel::class.java }
and, in the retriever, set the context: override val kodeinContext = kcontext(this)
, and finally retrieve it with val view: MyViewModel by instance<ViewModel>() as MyViewModel
Note that, as you can see, Kodein is not meant to be a sub-class factory. That's a popular demand, so I might look into that.