,我發現了以下錯誤:Ninject ActivationException:錯誤激活IAlertManagement
Test method: BootStrapperTest.Can_Create_Alert_Management_Object threw exception: Ninject.ActivationException:
Error activating IAlertManagement No matching bindings are available, and the type is not self-bindable.
Activation path:
1) Request for IAlertManagement
Suggestions:
1) Ensure that you have defined a binding for IAlertManagement.
2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.
3) Ensure you have not accidentally created more than one kernel.
4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.
5) If you are using automatic module loading, ensure the search path and filters are correct.
下面是導致此異常的測試用例:
[TestInitialize]
public void Initialize()
{
BootStrapper.RegisterTypes();
}
[TestMethod]
public void Can_Create_Alert_Management_Object()
{
IAlertManagement alertManagementService = BootStrapper.Kernel.Get<IAlertManagement>();
Assert.IsNotNull(alertManagementService);
}
//This is the code that gets called in [TestInitialize]
public static void RegisterTypes()
{
if (!initialized)
{
Kernel.Bind(scanner => scanner.FromAssembliesMatching("MyCompany.MyProduct.*")
.SelectAllClasses()
.BindDefaultInterface());
Kernel.Unbind(typeof(IWcfServiceClient<>));
Kernel.Bind(typeof(IWcfServiceClient<>)).ToMethod(ctx =>
(ctx.Kernel.Get(typeof(WcfServiceClientProvider<>).MakeGenericType(ctx.GenericArguments)) as IProvider).Create(ctx));
}
initialized = true;
}
上述錯誤中的一個發生我的單元測試我們的構建服務器,但不在我的開發機器上。我有7個其他測試幾乎完全相同,通過構建服務器和我的開發機器上的,但這是唯一的測試失敗。
的IAlertManagement接口從DLL來稱爲核心和具體類型是從另一個DLL來稱爲AlertManagement。我的單元測試項目中包含核心 dll和AlertManagement dll作爲項目參考。我有7或8個與這種情況相同的其他測試,但這是唯一的失敗。
任何想法都是值得讚賞的。
我確實在構建服務器上的drop文件夾中看到包含'IAlertManagement'的dll。我也嘗試切換單元測試類來使用'[ClassInitialize]'而不是'[TestInitialize]',但它似乎沒有幫助。我還沒有探索過選項3. – 2012-09-20 19:14:22
只是爲了進行測試,請嘗試將具體的AlertManagement放入您正在看到的程序集中,例如Core。例如,添加一個類的存根。然後你會知道它是否找不到該文件或者有其他的東西。 – 2012-09-21 17:10:17