2012-10-10 31 views
1

我有一個接口的一個具體的類由此Ninject - 讓一個接口

_ninjectKernal.Bind<IAuctionContext>().To<AuctionContext>() 

結合的結合我想在我的代碼做的就是具體的類接口IAuctionContext。所以我想要做這樣的事情

IAuctionContext context = .GetBinding();

其中context將是類型AuctionContext

這是可能的。過去我使用StructureMap做過類似的事情。

回答

3
// get access to the "container" 
IKernel kernel = new StandardKernel(.....); 

// use kernel, as you would any other container 
var context = kernel.Get<IAuctionContext>(); 

注 - 如果你正在使用依賴注入,你應該回避直接呼叫「內核」 Get(...)(或Container.GetInstance(...)在StructureMap)的距離。

+2

我同意你的最後一點。這個項目需要處理一些技術債務。 –