Ninject pass constructor argument typeof class that implements the interface

后端 未结 1 1356
醉梦人生
醉梦人生 2021-01-21 10:58

I am attempting to use Ninject with my application logging wrapper.

Here is the wrapper:

public class NLogLogger : ILogger
{
    private readonly Logger          


        
相关标签:
1条回答
  • 2021-01-21 11:51

    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);
    
    0 讨论(0)
提交回复
热议问题