2

したがって、私は具体的なクラスへのインターフェースのバインディングを持っています

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

私のコードでやりたいのは、インターフェースの具象クラスを取得することですIAuctionContext。だから私はこのようなことをしたい

IAuctionContext context = .GetBinding();

contextタイプはどこになりますかAuctionContext

これは可能ですか。私は過去にStructureMapで同様のことをしました。

4

1 に答える 1

4
// 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)を直接呼び出すことは避けてください。

于 2012-10-10T21:07:29.087 に答える