I use Log4net for logging and I have a lot of objects with an ILog dependency. These dependencies are injected just as the others. I would like to stick to the Log4net logger na
this and that covers your questions but they're not exactly duplicates, so i'll repost this:
Bind<ILog>().ToMethod(context =>
LogManager.GetLogger(context.Request.ParentContext.Plan.Type));
so context.Request.ParentContext.Plan.Type
is the type ILog
is injected into. If you ever want to do IResolutionRoot.Get<ILog>()
then there won't be a type to inject ILog
into and so there won't be a ParentContext
either. In that case you'll need the null
check as in your previous solution:
Bind<ILog>().ToMethod(context =>
LogManager.GetLogger(context.Request.ParentContext == null ?
typeof(object) :
context.Request.ParentContext.Plan.Type));