3
votes

I am successfully using Ninject in a project where I can have a class like this:

public class MyServiceConsumer
{
    [Inject]
    public void IPropertyInjectedService { get; set; }

    private IConstructorInjectedService _conSvc;

    public MyServiceConsumer(IConstructorInjectedService conSvc)
    {
        _conSvc = conSvc;
    }
}

And if I do kernel.Get<MyServiceConsumer>() the dependencies will be satisfied and everything will be fine. But there is one scenario with the starting up of the application where I already have an existing object, and I'd like to pass it to the kernel to have the kernel do property injection on that existing instance.

How do I pass an existing object to a Ninject kernel to have property injection dependencies satisfied?

1

1 Answers

5
votes

Figured it out. The syntax I was looking for is:

kernel.Inject(myExistingInstanceWithDependencies);