Common Service Locator Adapter Does Not Resolve Without a Name

167 views
Skip to first unread message

Thedric Walker

unread,
Jul 23, 2010, 12:23:38 PM7/23/10
to ninject-dev
The following test currently fails with an Activation Exception:

[Fact]
public ShouldResolveWithoutNameBeingGiven()
{
var kernel = new StandardKernel();
kernel.Bind<IWeapon>.To<Sword>();

var locator = new NinjectServiceLocator(kernel);

var weapon = locator.GetInstance<IWeapon>();

weapon.ShouldNotBeNull();
weapon.ShouldBeInstanceOf<Sword>();
}


The fix is a simple one. Change line 30 of NinjectServiceLocator.cs
to:
return key == null ? Kernel.Get(serviceType) : Kernel.Get(serviceType,
key);
Reply all
Reply to author
Forward
0 new messages