How can I get Castle Windsor to automatically inject a property?

萝らか妹 提交于 2019-12-04 19:53:30

问题


I have a property on my classes for logging service.

private ILogger logger = NullLogger.Instance;
public ILogger Logger
{
    get { return logger; }
    set { logger = value; }
}

And I have this in my component registration:

container.AddFacility<LoggingFacility>(x => new LoggingFacility(LoggerImplementation.Log4net));

However, Windsor doesn't seem to inject the Logger - am I missing something?


回答1:


The lambda parameter for AddFacility is actually a creation callback (it gets called when the facility is created), not a factory.

Use this instead:

container.AddFacility("logging", new LoggingFacility(LoggerImplementation.Log4net, "path_to_log4net.config"));

BTW Windsor automatically injects property dependencies whenever it can.



来源:https://stackoverflow.com/questions/1058785/how-can-i-get-castle-windsor-to-automatically-inject-a-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!