corbella83 / PopKorn

DI can be simple. Forget about modules and components. Just use it!
Apache License 2.0
155 stars 5 forks source link

Assisted Inject #7

Closed rvdsoft closed 3 years ago

rvdsoft commented 4 years ago

Would be nice if you added something like Assisted Inject.

 @AssistedInject
class MyPresenter(foo:String, @Assisted bar:String) {

  @AssistedInject.Factory
  interface Factory {
   fun create(bar:String): MyPresenter
  }
}
corbella83 commented 4 years ago

Hi rvdsoft,

I think PopKorn can achieve the same results with less code. If some parameters needs to be injected and some others don't, just add the ones you want to be injected by default:

@Injectable
class MyPresenter(foo:String, foo2:String = inject<String>()) *

You can then create your presenter like this: MyPresenter("some"). You don't need any factories.

*Notice that PopKorn can inject primitive types too (Int, Long, String...)

Thanks

corbella83 commented 3 years ago

Hi rvdsoft,

I'm glad to announce that version 2.1.0 introduces Assisted Dependencies:

@Injectable(BY_NEW)
class MyPresenter(@Assisted someId:Long, other:MyClass)

and to be used anywhere like this:

inject<MyPresenter>{ 
    assist(344L)
}