I’ve been using Ninject more and more. I also use log4net for logging. But how to do I get my log4net peanut butter into my Ninject chocolate? Like this:
Bind<ILog>().ToMethod(x => LogManager.GetLogger(x.Request.ParentContext.Plan.Type));
As far as I can tell, this is the simplest possible way to get Ninject to build an ILog object for dependency injection. NOTE! This is only valid for dependency injection! If you just call:
kernel.Get<ILog>();
You will be less than satisfied with the results… However, this works brilliantly:
public class Notifier : INotifier
{
private readonly ILog _log;
public Notifier(ILog log)
{
_log = log;
}
}
No wrappers, static classes or helper objects! If I ever meet Nate Kohari, I’m going to give him a big ol' hug. I may even tear up a little bit…


38 comments:
Never put both feet in your mouth at the same time, because then you will not have a leg to stand on.............................................
原來這世上能跟你共同領略一個笑話的人竟如此難得........................................
Hello~Nice to meet you~..................................................
沒有友情,人生何樂? ..................................................
思想與理論,貴呼先於行動,但行動較思想或理論更高貴..................................................
非常感謝~3Q~....................................................
cool blog,期待更新........................................
如此活躍的文字, 妳好棒哦! ....................................................
要保持更新呦,加油!!!期待你的新文章!!!........................................
憂能傷身,保重哦! ....................................................
Today is the first day of the rest of your life. ............................................................
Necessity is the mother of invention.............................................................
No pains, no gains...................................................................
初次拜訪,踩踩您的格子,跟您拜個碼頭囉~~.................................................................
知識可以傳授,智慧卻不行。每個人必須成為他自己。......................................................................
死亡是悲哀的,但活得不快樂更悲哀。.................................................................
當一個人內心能容納兩樣相互衝突的東西,這個人便開始變得有價值了。............................................................
向著星球長驅直進的人,反比踟躕在峽路上的人,更容易達到目的。............................................................
來幫推 你個blog影d相真係好靚,係我至愛~ ..................................................................
woo ~ woo ~ thx alotsˋε ˊ..................................................................
文章是心情的反應~~祝妳天天寫的都是讓人開心的好文章哦!!............................................................
Words are not living in dictionary. Words are living in mind.............................................................
脾氣與嘴巴不好,就算心地再好,也不算好人~~~..................................................
人並不是生來要吃敗仗的。人可被毀滅,但不可被擊倒。.................................................................
There is no key to happiness, only a ladder..................................................................
It is easier to get than to keep it.......................................................................
來看你囉~加油~~!!............................................................
Thank you for sharing this information,i am very happy with your updates.
small business logo design | design logo web | corporate logo designs | company logo designs
所有的資產,在不被諒解時,都成了負債.................................................................
相逢即是有緣~~留個言問候一聲,祝您平安順利...............................................................
困難的背後,隱藏著通往成功的階梯............................................................
Subtlety is better than force. ......................................................................
時間就是塑造生命的材料。..................................................... ............
文章是心情的反應~~祝妳天天寫的都是讓人開心的好文章哦!!...............................................................
人生像一杯茶,若一飲而盡,會提早見到杯底..................................................
來囉~先問聲安.................................[/url]...............
愛情是盲目的,但婚姻恢復了它的視力。......................................................................
睇完之後覺得有d頓悟..感謝大大分享..˙ 3˙............................................................
Post a Comment