gpt4 book ai didi

c# - With.Parameters.ConstructorArgument 与 ninject 2.0

转载 作者:IT王子 更新时间:2023-10-29 04:03:23 31 4
gpt4 key购买 nike

如何在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# - With.Parameters.ConstructorArgument 与 ninject 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1374098/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com