subcut icon indicating copy to clipboard operation
subcut copied to clipboard

Constructor with injected parameters not supported by newInstanceOf

Open frabass opened this issue 11 years ago • 0 comments

I read the documentation, changelog and scaladoc this is taken from the changelog:

"Subcut 2.0 now will inject no-constructor-parameter classes and also classes that require only an implicit binding module. It can't reflectively inject other constructor parameters (because, how would you? :-) )"

I'm not a reflection expert, but is not clear if this is technically impossible or not: Guice recursively injects constructor until gets to the point that knows how to build the injected object, can't subcut just do the same and look up the bindings its map? Again, don't know about facilities offered by Scala reflection, but since Guice does this in Java I expect it to be feasible in Scala as well.

The reason why this would be useful is so that you can always use bindIfMissing and in test just build the object calling the constructor passing teststubs as parameters without bothering messing with fake bindings.

On the other hand would probably make more complex what in Guice is called assisted injection (having part of the parameters in the constructor injected and part passed) which in subcut comes for free while in Guice is kind of painful probably because of the fact that it needs to always know exactly how to inject the constructor. https://code.google.com/p/google-guice/wiki/AssistedInject

Feel free to close this if it's either not feasible or too much work/out of scope, just wanted to understand if there's a technical block.

Thanks,

frabass avatar Sep 09 '13 09:09 frabass