Ninject 2015 年 Visual Studio 加载动态模块

Ninject dynamic module loading in Visual Studio 2015

我的项目是一个程序集,一个用 C# 完成的 .DLL。我没有前端所以,我只能在没有 运行 的情况下测试程序。这些测试在 class 到另一个项目中,我无法修改此测试 class 因为它是我的教授提供的 "as is" 并且包含在我的评估中。 (大学目的)

在我的装配项目中,我有一个这样的工厂:

public class BugTrackerFactory : IBugTrackerFactory
{
    public void BugTrackerInitialize(IPrincipal principal, string connectionString)
    {
        //code here
    }

    public IBugTracker LoadBugTracker(IPrincipal principal, string connectionString)
    {
        //code here
    }
}

public class BugModule : NinjectModule
{
    public BugModule() { }

    public override void Load()
    {
        this.Bind<IBugTrackerFactory>().To<BugTrackerFactory>();
    }
}

这些是另一个项目中的测试:

public static class Configuration
{
    public const string ImplementationAssembly =
        @"C:\Users\matte\Documents\Visual Studio 2015\Projects\BugTrackingSystem\BugTrackingSystem\bin\Debug\BugTrackingSystem.dll"; //this is my path to assembly project

}

[TestFixture]
public abstract class TestRoot {
    protected static readonly IBugTrackerFactory Factory;
    .....
    .....
    //all code initializations for testing purpose


    static TestRoot() {
        var kernel = new StandardKernel();
        try {
            kernel.Load(Configuration.ImplementationAssembly);
            Factory = kernel.Get<IBugTrackerFactory>();
        } catch (Exception e) {
            Debug.WriteLine(e);
        }
    }

    ...
    ...
    //all the tests

使用此配置,我在尝试使用 Nunit 启动测试时总是遇到以下错误:

    One or more child tests had errors
Exception doesn't have a stacktrace

Ninject.ActivationException: Error activating IBugTrackerFactory
No matching bindings are available, and the type is not self-bindable.
Activation path:
  1) Request for IBugTrackerFactory

Suggestions:
  1) Ensure that you have defined a binding for IBugTrackerFactory.
  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.

   in Ninject.KernelBase.Resolve(IRequest request)
   in Ninject.ResolutionExtensions.Get[T](IResolutionRoot root, IParameter[] parameters)
   in BugTrackerTests.TestRoot..cctor() in C:\Users\matte\Documents\Visual Studio 2015\Projects\BugTrackerTests\BugTrackerTests\BasicTests.cs:riga 37

我真的不知道该怎么办,这里有人可以帮助我吗?谢谢

解决了信不信我没编..完全忘了!!无论如何谢谢你..