corbella83 / PopKorn

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

Error when try to inject a class that inherits an generic abstract class #23

Open danielriverolosa opened 3 years ago

danielriverolosa commented 3 years ago

Hello,

I am getting an error when trying to make @Injectable a class that inherits an abstract class that has generic parameters.

This is the class injectable:

@Injectable(scope = Scope.BY_USE)
class GetContactListUseCase(private val repository: ContactRepository): UseCase<Contact, Filter>() {

    override suspend fun run(params: Filter): User {
        return repository.getContactList(params)
    }

}
abstract class UseCase<Type, in Params> where Type: Any {

    protected abstract suspend fun run(params: Params): Type

    suspend operator fun invoke(params: Params): Result<Type> {
        return withContext(ioDispatcher) {
            try {
                successOf(run(params))
            } catch (e: Exception) {
                failureOf(RuntimeException("Use case error => ${e.message}"))
            }
        }
    }
}

And this is the error I am getting when I try to compile.

2 type arguments expected for class UseCase<Type : Any, in Params>