我正在尝试将Ninject与我的WCF服务一起使用。我正在使用Ninject 2.2.1.4和Ninject.Extensions.Wcf 2.2.0.4。我的单元测试,以确保Ninject正常工作失败,带有ArgumentNullException;参数root:null。Ninject + WCF问题
这里是我的代码:
//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);
}
全球只是一个类,而不是global.asax ...不知道这是否导致问题(我是一个Web服务noob)。你能提供一些代码来帮助我纠正并让我的单元测试通过吗?我不完全清楚,谢谢。 – Mike
全局派生自NinjectWcfApplication,它是一个无法使用的初始化的HttpApplication。请参阅https://github.com/ninject/ninject.extensions.wcf/tree/Maintenance_2.2/src –