Bad Design? Constructor of composition uses `this`
- by tanascius
Example:
class MyClass
{
Composition m_Composition;
void MyClass()
{
m_Composition = new Composition( this );
}
}
I am interested in using depenency-injection here. So I will have to refactor the constructor to something like:
void MyClass( Composition composition )
{
m_Composition = composition;
}
However I get a problem now, since the Composition-object relies on the object of type MyClass which is just created.
Can a dependency container resolve this? Is it supposed to do so?
Or is it just bad design from the beginning on?