Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InjectProperties() is skipping children? #553

Open
aggiehorns opened this issue Jan 13, 2021 · 0 comments
Open

InjectProperties() is skipping children? #553

aggiehorns opened this issue Jan 13, 2021 · 0 comments

Comments

@aggiehorns
Copy link

aggiehorns commented Jan 13, 2021

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant