【发布时间】:2011-07-12 12:26:20
【问题描述】:
我正在尝试将 Ninject 与我的 WCF 服务一起使用。我正在使用 Ninject 2.2.1.4 和 Ninject.Extensions.Wcf 2.2.0.4。我确保 Ninject 正常工作的单元测试因 ArgumentNullException 而失败;参数根:null。
这是我的代码:
//A couple of classes to setup ninject and its bindings
public class NinjectBindings : NinjectModule
{
public override void Load()
{
Bind<IEmployeeRepository>().To<SqlEmployeeRepository>().InSingletonScope();
}
}
public class Global : NinjectWcfApplication
{
protected override IKernel CreateKernel()
{
IKernel kernel = new StandardKernel(new NinjectBindings());
return kernel;
}
}
//Test method that fails with ArgumentNullException
[TestMethod]
public void Should_Be_Able_To_Get_Employee_Service_From_Ninject()
{
Global globalService = new Global();
var kernel = globalService.Kernel;
EmployeeService employeeService = kernel.Get<EmployeeService>();
Assert.IsNotNull(employeeService);
}
【问题讨论】:
标签: asp.net-mvc wcf unit-testing ninject