Valera Fedorenko
Valera Fedorenko

Reputation: 99

Is some way out of box resolve bindings inside property using ninject

I am interesting about way out of box to resolve this example:

example:

class A { public B someProperty {get;set;} }

class B { public IResolve needResolve {get;set;} }

class C:IResolve {}

class D:IResolve {}

When I set binding like:

 IKernel kernel = new StandardKernel();
kernel.Bind<IResolve>().To<C>();

And when I Get type 'A'

var res = kernel.Get<A>();

should be :

res.someProperty.needResolve.GetType() // typeof(C)

PS: I read about way to resolve property by [inject] attribute. But it works only with a property that type which we try to resolve. I understand how I can resolve it(e.g: Reflection), but I try to found the best solution

Upvotes: 1

Views: 51

Answers (1)

Jan Muncinsky
Jan Muncinsky

Reputation: 4408

This one works for me:

class A
{
    [Inject]
    public B someProperty { get; set; }
}

class B
{
    [Inject]
    public IResolve needResolve { get; set; }
}

res.someProperty.needResolve is of type C.

Upvotes: 2

Related Questions