I am new to Ninject and am struggling to get this test to pass. (This test passed with Autofac but the behaviour seems different in Ninject).
[Test]
public void RegisterInstance_unnamed_should_return_unnamed_when_multiple_registrations()
{
var sut = new StandardKernel();
var instance1 = new Dependency3();
var instance2 = new Dependency3();
sut.Bind<Dependency3>().ToConstant(instance1).Named("instance1");
sut.Bind<Dependency3>().ToConstant(instance2);
sut.Get<Dependency3>("instance1").ShouldBeSameAs(instance1);
sut.Get<Dependency3>().ShouldBeSameAs(instance2);
}
When I call the last line I get this exception message:
Ninject.ActivationException : Error activating Dependency3
No matching bindings are available, and the type is not self-bindable.
Activation path: 1) Request for Dependency3
How do I resolve a binding that is not named when there are multiple bindings?
Thanks