pass clientProvider to TestService?
# announcements
m
pass clientProvider to TestService?
t
Maybe make the TestService a lateinit val and initialize it in an init { } block when you have the cleintProviderInterface available
h
thanks can you i tried but got an error saying
late init
modifier is not allowed on primary constructor parameters
can you provide example as I think I may have misunderstood?
t
Oh, sorry, turns out lateinit can't be in the constructor. Why do you need to pass so many things in the constructor though, surely you can build the needed dependency and then pass it
m
nah, I re-read the code. i don't think my suggestion would help, as you depend on other stuff to generate the client
h
yep I tried passing in the clientProvider to TestService and it didnt work too
I guess my whole Handler class architecture is wrong or what? Maybe there's another way
m
but why do you have 2 testServices? can't you use the one you got in the constructor at line 9?
h
Ah my mistake
yes the other testService is not needed
I only need the one in the constructor
m
ah ok. can you refactor it so the constructor doesn't depend on the client?
t
I don't see why you're passing in the clientProvider as well as the testService
either just pass the provider and build the service inside or build it outside and pass it in
h
@Matheus you mean refactor so that I remove this line completely
val testService: TestService = TestServiceImpl(client))
m
The problem is that you need a client, which is built on TestHandler's constructor, to build another dependency from TestHandler. So either do that outside this class (build the client and build TestService), or make it so that TestService's constructor doesn't depend on client (maybe the methods could receive a client? can't really say much without seeing the rest of the code).
h
okay, just for my understanding if I just not inject
testService
in the constructor. and I use
val testService: TestService = TestServiceImpl(client)
in line 9 that would make my Handler less testable as Im depending on a concrete implementation, is that right? @Matheus
m
yes, you wouldn't be able to mock TestService to test this class