I have an Order class with the below constructor
public Order(IProduct product, short count)
{
this._product = product;
this._count = count;
}
I'm trying to setup Unity IoC container and obviously to construct the order object I'd need to know the count and product but these are determined at run time; the count could be any value and product can be any product e.g. Carrot, Melon, etc.
So how to apply IoC for this?
One approach I thought was that my constructor only accepts object dependencies then any other required property to be added using a new Initialize() method:
public Order (IProduct product)
{
this._product = product;
}
public Initialize(short count)
{
this._count = count;
}
in this way whoever creates the Order object, has to call the Initialize() method afterwards so that other properties that can't be handled by the IoC container be added to it.
Is it the approach that you recommend/use?