Ninject pass constructor argument typeof class that implements the interface

妖精的绣舞 提交于 2019-12-02 02:43:56

Assuming that your classes look like this:

public class EntityObject
{
    public ILogger Logger { get; set; } //it is better by the way to convert this into a private field

    public EntityObject(ILogger logger)
    {
        Logger = logger;
    }
}

You would need to register your NLogLogger like this:

Bind<ILogger>().To<NLogLogger>()
    .WithConstructorArgument(
        typeof(Type),
        x => x.Request.ParentContext.Plan.Type);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!