我有這樣的事情:進樣值到注入依賴
class Root
{
public Root(IDependency dep)
{}
}
class Dependency:IDependency
{
public Dependency(int val)
{}
}
而我試圖獲得使用ninject到根的引用。 所以我配置它這樣
var module = new InlineModule(mod => mod.Bind<IDependency>().To<Dependency>());
var kernel = new StandardKernel(module);
我想注入依賴的是僅在獲得來自ninject根引用的那一刻知道一些「VAL的價值。
我希望做的是這樣的:
Kernel.Instance.Get<Root>(With.Parameters.ConstructorArgument("val", 12));
是使用ninject 1.0這樣的事情可能嗎?
我想我能做到這一點更多的只是想: 綁定()。爲了().WithConstructorArgument( 「VAL」(IContext續)=> \t \t cont.ParentContext.Parameters。獲得( 「VAL」)); 但我不喜歡使用ParentContext。 :(它 –
Silviu
2010-02-01 07:15:36
@Silviu:試試吧 - 越短越好,這對我來說似乎是有道理的,就像你直接問你的問題一樣,但是我不能在我嘗試它的情況下爲它工作 – 2010-02-01 08:50:20
@ Silviu:你是否把它作爲「綁定」的一部分來完成呢?如果你想挑選一些可以用於評論的東西,我會把它放到例子中。 – 2010-02-11 08:40:45