Suppose we have 2 classes: Car and Engine. Engine depends on Car - when the car is destroyed, Engine also. How to correctly express Engin's dependence on Car? The relationship is that the Engine class does not make sense outside of Car. In my opinion, injection of Engine indicates some independence from Car. Which Car constructor is correct in this case? With DI or without?
Example code:
interface IEngine { }
class Engine : IEngine { }
class Car
{
private readonly IEngine _engine;
public Car()
{
_engine = new Engine();
}
public Car(IEngine engine)
{
_engine = engine;
}
}