subcut icon indicating copy to clipboard operation
subcut copied to clipboard

Support for module installation

Open frabass opened this issue 12 years ago • 1 comments

Currently in order to add more bindings you can either combine modules (~/andThen) or mergeWithReplace (also withBindingModules but has the limitation that applies only to empty modules)

Problem with 1: it returns a combined module so you'll end up having to manually combine in the main module all your submodules

Problem with 1 and 2: mergeWithReplace allows you to distribute module installation as in Guice and mix it into modules that already contain bindings which is nice Eample Mod A: bind a to ... bind b to ... withMergeReplace(Mod B)

ModB bind c to ... etc...

The only problem is that both andThen and mergeWithReplace apply overriding policies and so you could end up wiping a binding without knowing it because the project is broad, Guice throws an exception at runtime complaining about accidental (not forced override) double bindings.

Would it be possible to add something similar to Guice binder.install? Which basically is exactly withMergeReplace without replacing and signaling an accidental double binding.

http://google-guice.googlecode.com/git/javadoc/com/google/inject/Binder.html#install(com.google.inject.Module)

Thanks

frabass avatar Sep 09 '13 09:09 frabass

I am intrigued by this idea. I wonder if a ++ for the val composition, and a strictMerge in the module definition would provide safe alternatives if people did not want to accidentally re-bind. I will give it a bit more thought but I think that might fly

val c = a ~ b would be fine if a and b have clashing bindings, but val c = a ++ b would complain in the same situation

not crazy about the operator choice yet though, so I will give it some more thought before implementing

dickwall avatar Feb 12 '14 15:02 dickwall