我不能找到一種方法,在這種情況下注入參數:統一進樣參數beeing解決
class Top
{
private ISome some;
public Top()
{
some = CreateSome(localRuntimeVariable);
}
//I need to pass "some" instance as a InjectionParameter to Child constructor
[Dependency]
public Child Child {get;set;}
}
class Child
{
//I need to inject ISome but it can only be constructed in Top
public Child(ISome some, Foo foo)
{
}
}
public class Usage
{
private void Top GetTop(Foo foo)
{
return unity.Resolve<Top>(new DependencyOverride<Foo>(foo));
//I expect: Top.Constuctor called and 'some' is assigned;
// Top.Child property beeing resolved: Child.Constructor called
// 'foo' instance to be taken from unity.Resolve<Top>(new DependencyOverride<Foo>(foo));
// 'some' instance to be taken from Top.some, but how to tell unity to inject it?
}
}
解析語句在哪裏?在調用Resolve時已知哪些引用? – PVitt
是的,我看到了這一行。但是在哪個上下文中調用?請把整個方法。調用解析時可以使用哪些引用? – PVitt
@PVitt更新了問題。 –