Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service from base class #548

Closed
dshatz opened this issue May 7, 2024 · 4 comments
Closed

Service from base class #548

dshatz opened this issue May 7, 2024 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@dshatz
Copy link

dshatz commented May 7, 2024

Is your feature request related to a problem? Please describe.
I am trying to make a Ktorit service that would extend a base service.
Example:

// common service for all build variants
interface BaseMessageService {
    @GET(...)
    suspend fun baseCall(): String
}

// extended implementation for e.g. a different client
interface CustomMessageService {
   @GET(...)
   suspend fun otherCall(): Double
}

The goal is to have a CustomService on which both baseCall and otherCall are available.
Ksp compiles but I am getting this runtime error when calling CustomMessageService.baseCall():

kotlin.UninitializedPropertyAccessException: lateinit property _converter has not been initialized
at _BaseMessageServiceImpl.get_converter
at _BaseMessageServiceImpl.baseCall
at _CustomMessageServiceImpl.baseCall

Creating CustomMessageService as usual ktorfit.create<CustomMessageService().

Describe the solution you'd like
The error makes sense - the generated CustomMessageServiceImpl extends BaseMessageService by _BaseMessageServiceImpl(). That new instance does not have the _converter because it is created by create which is not called here.
Not sure what the solution could be. I understand this usecase is not supported now? I may try to hack something.

Describe alternatives you've considered

  • Copy paste base service methods to all extending services.
  • Abandon the idea of extending and just have two separate services.
@dshatz dshatz added the enhancement New feature or request label May 7, 2024
@Foso
Copy link
Owner

Foso commented May 16, 2024

Hi, that was working once, but it looks like it got broken. I fixed it and it will work again with >= 2.0.0-beta2

@sschuberth
Copy link

Release 2.0.0 says this was fixes... so I guess the issue should be closed?

@Foso
Copy link
Owner

Foso commented May 28, 2024

@sschuberth You are right, thanks

@Foso Foso closed this as completed May 28, 2024
@Foso Foso added this to the 2.0.0 milestone May 28, 2024
@dshatz
Copy link
Author

dshatz commented May 28, 2024

Maybe a good idea to document that this is supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants