InjectProperties() is skipping children?
aggiehorns opened this issue · 0 comments
aggiehorns commented
I am trying to do something like this. I'm a little confused because I swear LightInject supported this, but not working for me. Very simply, when calling InjectProperties(obj) on some object, I want it to scan the full nested structure and inject everything. So inject properties of property objects. Inject properties of objects in collections. And so on. Thanks!
public class InjectableObject
{
[Inject]
public IFoo _foo { get; set; }
private readonly Guid _id;
public Guid Id => _id;
public InjectableObject()
{
_id = Guid.NewGuid();
}
}
public class InjectableObjectWithCollection
{
[Inject]
public IFoo _foo { get; set; }
public List<InjectableObject> MyCollection { get; set; }
public InjectableObject Test { get; set; }
public InjectableObjectWithCollection()
{
MyCollection = new List<InjectableObject>();
MyCollection.Add(new InjectableObject());
MyCollection.Add(new InjectableObject());
Test = new InjectableObject();
}
}
var objectWithCollection = new InjectableObjectWithCollection();
container.InjectProperties(objectWithCollection);