Hi guys! i fell in love with http4k for its simpli...
# http4k
s
Hi guys! i fell in love with http4k for its simplicity. Now i am looking for a dependency injection solution for it. Koin seems to be the kool kid in school right now. However i hardly find anyone talking about it in the context of backend/server side of things. i feel like Koin has similar philosophies as http4k has (simplicitly, explicit over implicit, no magic) and might be a good fit here. Code generation things like dagger i do not really like and these sorts of things were the reason why i even started moving away from spring boot/java stack. what are you guys using?
d
Hey! Glad to hear you're enjoying the library🙃. Its a pretty simple answer - we only ever use pure manual constructor injection for building our apps. We find that as well as being too magic, a DI container doesn't give us any actual advantage, and in fact stops us from factoring our apps in the best way because it can hide the complexity of how systems are constructed. Not bring able to see/listen to the valid signals that the code is giving you means you miss opportunities to refactor and pull out abstraction etc. Plus, no DI means that things start super quick, are as simple as they look, and also sidesteps us having conversations about which DI system is best. 😉
s
Thats actually the best answer i could have wished for! you would then have basically a setup part of your application where you initialize the services you have and push them downstream to your request handlers that need them explicitly?
is there any example which does showcase that for a more complex scenario than a "repository method" for getting an entity?
d
Yep. The pattern that you see in Http4k-by-example is pretty much what we use
s
alright, i will read more into the code in this repo. already checked it out for playing
thx a lot for your quick replies!
t
I'm using guice as DI library now, and quite happy about it. And of course you can use pretty much any DI library you like with http4k.
I also use http4k-by-example as guidline. Just added more functional patterns with Arrow, DI and a real database layer.
274 Views