I'm trying to understand which objects should be injected into an object and which should be created internally.
- If i have some
List<int>
(as data field) which holds infomation gathered during run time. it seems that i should init it in the c'tor instead of injecting it.
but what about a hardware class which communicates through a COM port.
do i let the HW class init the SerialPort or i inject it ?
- If the above mentioned SerialPort needs to be injected; what is the best way to do it ?
do i create it manually :
SerialPort port = new SerialPort(name, baud ...);
HWClass hwClass = container.Reolve<IHWClass>("HWClass", new InjectionConstructor(port));
or using the Unity container
SerialPort port = conatiner.Resolve<SerialPort>(...);
HWClass hwClass = container.Reolve<IHWClass>("HWClass", new InjectionConstructor(port));
or should i init it inside the HWClass C'tor ?
adiel