Open mgth opened 3 years ago
Hi @mgth
Grace makes some trade offs to achieve the performance it does. One of those trade off is that it's going to pick one constructor for an object and stick with it. For corner cases like this it's not going to work very well.
Let's take a step back though because constructor injection is supposed to be the contract specifying the dependencies an object depends on to be constructed. What does it say when there are two constructors with two different parameter types?
My general rule of thumb these days is to have one constructor. If you want/need multiple have one main constructor that take all parameters and the others call the main constructor. That said it's usually far easier and more descriptive to have one constructor/one way to construct an object.
I understand the point, I ended up with creating two inherited classes, one for each case. Not as elegant in my case but maybe more readable, so it's ok. Thank you for the time pasted.
I expected constructor two to be used with parameter of type ClassB but grace injects a newly created ClassA in the first constructor instead.