我正在嘗試將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 –