Lightweight and Nonintrusive Scala Dependency Injection Library
I'm considering to use macwire
init and wiring works nice
is there any support for other module lifecycle events, like close?
no, you'd have to do it yourself
as there's no container the module doesn't really have any "managed" lifecycle beyond creation :)
but you could e.g. add a close() method to your module and there do any cleanup
ok, clear, thanks
maybe a macro or something is possible
which I could use in close method of a module
which would inspect all vars of module, and ones which implement e.g. AutoClosable, code would be generated that calls close on them
and respect order of instantiation, to call close in reverse order
yeah more generally something that returns a set/list of all members that are a subtype of a given type
I think there's an issue for that ...
quite old even :) #8
could filter, and map in close
for each AutoClosable, call close
but without this order constraint, that they get closed inverse to order of instantiation
that could be tricky
to get the order of instantiation
and what about a method
registerForClosing(t: T): T
in which all values which require closing would have to be wrapped
that would capture the correct order
the registerForClosing would add the instance to a list and return it unmodified
wire macro could generate those registerForClosing calls automatically, given condition is met that object is a subtype of AutoClosable
I have usecase question for the wire macro. Most of my Compontents take configuration options (eg. Database name) and other components (eg. Excution context) as a parameter. Now I'd like to use wire in order to provide the components but not the configuration options. Is that even possible?
My rational is that most of the config options are Strings so that would require to tag them all ... which would result in basically writing down a copy of the config file it self mapping all the paths in the config like "system1.database.name" to tags like "System1DatabaseName"
Or is there maybe an other way to avoid this? (Maybe a integration with typesafe config to automatically tag values?)
@slomo that's a very good question and I think currently it's not supported. The main problem is that you would like to have some parameters of a component automatically wired, and this causes two issues: