私のWCFサービスでNinjectを使用しようとしています。私はNinject 2.2.1.4とNinject.Extensions.Wcf 2.2.0.4を使用しています。 Ninjectが正常に動作していることを確認するためのユニットテストは、ArgumentNullExceptionで失敗します。パラメータルート:nullここでNinject + WCF Issue
は私のコードです:
//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ではありません。問題が発生しているかどうかはわかりません(私はウェブサービスの悩みです)。あなたが私のユニットテストに合格するためのコードを提供できますか?私は完全に明確ではない、ありがとう。 – Mike
グローバルは、使用できないHttpApplicationであるNinjectWcfApplicationから派生しています。 https://github.com/ninject/ninject.extensions.wcf/tree/Maintenance_2.2/srcを参照してください。 –