jeudi 19 novembre 2015

Ninject Get

Here is my Module:

public class LoggerModule : NinjectModule
{
    public override void Load()
    {
        Bind<ILogger>().To<NLogLogger>()
            .WithConstructorArgument(
                typeof(Type),
                x => x.Request.ParentContext.Plan.Type);
    }
}

So as you can see the NLogLogger is expecting the Type to be passed into the constructor.

This is my Unit Test:

    [Test]
    public void ResolveLoggerDependency()
    {
        var module = new LoggerModule();
        var kernal = new StandardKernel(module);
        var service = kernal.Get<ILogger>(new ConstructorArgument("type", typeof(int)));
        Assert.That(service, Is.Not.Null);
    }

It is throwing a null reference error on the kernal.Get<ILogger> so I can only assume I am not passing the constructor value correctly. How can I pass in a Type when using Get<T>?

Aucun commentaire:

Enregistrer un commentaire