Hi there,
So here's my factory method which takes a parameter...
container.RegisterInstance<Func<IProductInstance, IQuantityModifier[]>>(
instance => container.Resolve<IQuantityModifier[]>());
Now one of the items returned by the array takes the IProductInsance parameter in its constructor. I can't figure out how to get Unity to pass the parameter in or, if I make the constructor argument a property instead, how to get Unity to set the property. No amount of dependency overrides, injection parameters etc. seem to do anything.
Of course both of these situations would be easy if I was resolving a single instance but with an array Unity doesn't seem to fully process each item.
Any ideas? What I've ended up doing is stuff like this...
container.RegisterInstance<Func<IProductInstance, IQuantityModifier[]>>(
instance =>
{
var items = container.Resolve<IQuantityModifier[]>();
QuantityModifier item = items.OfType<QuantityModifier>().SingleOrDefault();
if (item != null)
{
item.ProductInstance = instance;
}
return items;
};
I suppose ideally the item that requires the parameter would be created by a factory but then Unity would have to pass the correct value into the factory and execute it.
Cheers, Ian.