public void ConstructorArgumentWithMatchingTypeShouldBeUsedIfUsingCallbackWithContextAndTarget() { var expectedWeapon = new Shuriken(); this.kernel.Bind<Samurai>().ToSelf().WithConstructorArgument(typeof(IWeapon), (context, target) => expectedWeapon); var samurai = this.kernel.Get<Samurai>(); samurai.Weapon.Should().Be(expectedWeapon); }
public void GivenADefaultAndAConditionalBinding_AllBindingsWillResolve() { var shortSword = new ShortSword(); var shuriken = new Shuriken(); kernel.Bind<IWeapon>().ToConstant(shortSword); kernel.Bind<IWeapon>().ToConstant(shuriken).When(_ => true); var result = kernel.GetAll<IWeapon>(); result.Should().Contain(shortSword); result.Should().Contain(shuriken); }
public void GivenAMixtureOfBindings_OnlyNonImplicitBindingsWillResolve() { var shortSword = new ShortSword(); var sword = new Sword(); var shuriken = new Shuriken(); kernel.Bind<IWeapon>().ToConstant(shortSword); kernel.Bind<IWeapon>().ToConstant(sword); kernel.Bind<IWeapon>().ToConstant(shuriken).Binding.IsImplicit = true; var result = kernel.GetAll<IWeapon>(); result.Should().Contain(shortSword); result.Should().Contain(sword); result.Should().NotContain(shuriken); }
public void GivenOnlyImplicitBindings_AllBindingsWillResolve() { var shortSword = new ShortSword(); var shuriken = new Shuriken(); kernel.Bind<IWeapon>().ToConstant(shortSword).BindingConfiguration.IsImplicit = true; kernel.Bind<IWeapon>().ToConstant(shuriken).BindingConfiguration.IsImplicit = true; var result = kernel.GetAll<IWeapon>(); result.Should().Contain(shortSword); result.Should().Contain(shuriken); }