如何在ninject 2.0中使用此功能?

MyType obj = kernel.Get<MyType>(With.Parameters.ConstructorArgument("foo","bar"));

“With”不存在:(

最佳答案

   [Fact]
   public void CtorArgTestResolveAtGet()
   {
       IKernel kernel = new StandardKernel();
       kernel.Bind<IWarrior>().To<Samurai>();
       var warrior = kernel
           .Get<IWarrior>( new ConstructorArgument( "weapon", new Sword() ) );
       Assert.IsType<Sword>( warrior.Weapon );
   }

   [Fact]
   public void CtorArgTestResolveAtBind()
   {
       IKernel kernel = new StandardKernel();
       kernel.Bind<IWarrior>().To<Samurai>()
           .WithConstructorArgument("weapon", new Sword() );
       var warrior = kernel.Get<IWarrior>();
       Assert.IsType<Sword>( warrior.Weapon );
   }

关于c# - 带ninject 2.0的With.Parameters.ConstructorArgument,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1374098/

10-12 19:58